Last active
June 3, 2018 16:37
-
-
Save ryanguill/27f8212d9c6c1e84383b8948388b972b to your computer and use it in GitHub Desktop.
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> |
verified now on ACF 11 and 2016
10 probably doesnt work because of an older JVM, but thats just a guess.
Good introduction to how you can work back and forth between java and javascript here: http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
verified working on lucee 4.5