Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2017 17:59
Show Gist options
  • Save anonymous/7dd6f321bc9e3d2ac52e94577db18801 to your computer and use it in GitHub Desktop.
Save anonymous/7dd6f321bc9e3d2ac52e94577db18801 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
function prettyPrintJSON (inputJSON) {
var engine = createObject("java","javax.script.ScriptEngineManager").init().getEngineByName("nashorn");
engine.eval("
function prettyPrintJSON (data) {
return JSON.stringify(JSON.parse(data), null, '\t');
}
");
return engine.invokeFunction("prettyPrintJSON", [inputJSON]);
}
</cfscript>
<cfsavecontent variable="myJSON">
{"a":1,"b":"foo","c":[true,false,null,"null",{"d":{"e":130000,"f":1.3e5}}]}
</cfsavecontent>
<cfoutput>
<textarea style="width:100%; height: 100%">#prettyPrintJSON(myJSON)#</textarea>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment