Jsoneditor: How do i know that JSON is valid or not

Created on 26 May 2017  路  6Comments  路  Source: josdejong/jsoneditor

I want to check the json in jsoneditor is valid or not. i am getting errors in console.log if any error

question

Most helpful comment

try {
  var json = jsoneditor.get();
  console.log('JSON is valid', json);
}
catch (err) {
  console.error('JSON is invalid', err);
}

All 6 comments

If you try to get the JSON via jsoneditor.get(), and error will be thrown when invalid, and JSON will be returned when valid.

what it will return if error occurred, if no errors all good. but if any error raises i wanted to catch the error . how can i achieve this. help is appriciated. thank you

try {
  var json = jsoneditor.get();
  console.log('JSON is valid', json);
}
catch (err) {
  console.error('JSON is invalid', err);
}

That works for me Thanks a lot

ok

it's great!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricardogaspar2 picture ricardogaspar2  路  3Comments

realtebo picture realtebo  路  3Comments

sergibondarenko picture sergibondarenko  路  4Comments

guiferrpereira picture guiferrpereira  路  6Comments

shinyamade picture shinyamade  路  5Comments