JSFiddle - React, Tailwind, and code Playground
HTML
<dl id="results"></dl>
CSS
dt { margin-top: 1ex; }
JavaScript
var json = '1,["Oops!"]';
if ( window.JSON ) {
demonstrate( json, "native" );
window.JSON = undefined;
}
demonstrate( json, "jQuery" );
function demonstrate( json, detail ) {
var $results = $("#results");
$results.append( "<dt>" +
( detail ? detail + " " : "" ) +
"parseJSON(<code>'" + json + "'</code>)" +
"</dt>" );
try {
$results.append( "<dd>" +
$.parseJSON( json ) +
"</dd>" );
} catch ( x ) {
$results.append( "<dd>ERROR: " +
x.message +
"</dd>" );
}
}