JSFiddle - React, Tailwind, and code Playground
JavaScript
// Thanks to: http://stackoverflow.com/a/3710226/2010246
function IsJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
// And http://stackoverflow.com/a/22482737/2010246
function isObject(val) {
if (val === null) { return false;}
return ( (typeof val === 'function') || (typeof val === 'object') );
}
var Json = "[[0,1],[1,2],[2,3]]"; // in chart: [[x=0,y=1],[x=1,y=2],[x=2,y=3]]
var isCorrect = IsJsonString(Json);
console.log('a JSON string: ' + Json);
console.log('is this correct JSON: ' + isCorrect);
console.log('can I use it? ' + isObject(Json));
// Fix time
Json=JSON.parse(Json);
console.log('can I use it now? ' + isObject(Json));