Quantcast
Channel: Lucee Dev - Latest topics
Viewing all articles
Browse latest Browse all 564

Demo: JSON pretty printing with Lucee 6.2

$
0
0

I’m working on updating cfdocs.org with all the newer and missing Lucee tags and functions, by producing json files for each one, as part of the Lucee docs build.

https://luceeserver.atlassian.net/browse/LDEV-5520

Problem was the JSON needed to be pretty printed, so using the lovely new java support in 6.2, I had a solution in a few minutes

<cfscript>

function getJsonPrettyPrinter(){
		return new component javasettings='{
			"maven": ["org.json:json:20240303"]
		  }' {
			import org.json.JSONObject;
			function prettyPrint( jsonString ){
				var jsonObj = new JSONObject( jsonString );
				var str = jsonObj.toString( 4 );
				return str;
			}
		}
	}
	var json = server.lucee;
	var pretty = getJsonPrettyPrinter().prettyPrint( json );
	
</cfscript>
<cfoutput>
    <pre>#json.toJson()#</pre>
    <hr>
    <pre>#pretty#</pre>
</cfoutput>

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 564

Trending Articles