@@ -205,7 +205,8 @@ void openJSONDialog()
205
205
delete[] curJSON;
206
206
}
207
207
208
- void formatSelectedJSON () {
208
+ void formatSelectedJSON ()
209
+ {
209
210
// Get the current scintilla
210
211
int which = -1 ;
211
212
::SendMessage (nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0 , (LPARAM)&which);
@@ -234,9 +235,25 @@ void formatSelectedJSON() {
234
235
rapidjson::StringStream ss (curJSON);
235
236
rapidjson::Reader reader;
236
237
237
- reader.Parse <rapidjson::kParseFullPrecisionFlag >(ss, pw);
238
- const char * fJson = sb.GetString ();
239
- ::SendMessage (curScintilla, SCI_REPLACESEL, 0 , (LPARAM)fJson);
238
+ if (reader.Parse <rapidjson::kParseFullPrecisionFlag >(ss, pw))
239
+ {
240
+ const char * fJson = sb.GetString ();
241
+ ::SendMessage (curScintilla, SCI_REPLACESEL, 0 , (LPARAM)fJson);
242
+ }
243
+ else
244
+ {
245
+ // Mark the error position
246
+ // Get the current scintilla
247
+ start = ::SendMessage (curScintilla, SCI_GETSELECTIONSTART, 0 , 0 );
248
+
249
+ size_t errPosition = start + reader.GetErrorOffset ();
250
+ ::SendMessage (curScintilla, SCI_SETSEL, errPosition, errPosition + end);
251
+
252
+ // Intimate user
253
+ ::MessageBox (nppData._nppHandle,
254
+ TEXT (" There was an error while parsing JSON, refer the current selection for possible problematic area." ),
255
+ TEXT(" JSON Viewer" ), MB_OK | MB_ICONERROR);
256
+ }
240
257
241
258
delete[] curJSON;
242
259
}
0 commit comments