Search code examples
jsonserializationformatcoldfusion-10

How improve readability of JSON string formatting when or after using SerializeJSON


Using ColdFusion 10, I created a struct and returned a JSON string after using SerializeJSON.

    <cfreturn serializeJSON(stcResult)>

The string returned looks like this:

{"errors":[{"key1":"value1"},{"key2":"value2"}]} 

I want the JSON to look something like the example below. How can I format it with different indentation levels, so it is more readable?

{
    "errors":[
        {"key1":"value1"},
        {"key1":"value1"}
    ]
} 

Thanks in advance.


Solution

  • I found a solution, just need to change '+' to '&' and change '&nbsp;' to ' ' or chr(32) when using CFSCRIPT.