Created
May 1, 2017 17:59
-
-
Save anonymous/7dd6f321bc9e3d2ac52e94577db18801 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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