Docly Developers
Function Updated 23 Oct 2026

JSON.format(json)

Outputs specified JSON string to "prettified" indented JSON.

To indent while converting a value, JSON.stringify(value, null, 2) does it in one step, with plain line breaks — there is no carriage return to remove.

Parameters

jsonstringrequired

JSON string to format.

Returns

The formatted JSON string.

Example

Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
    var object = {
        "Name" : "Abcd",
        "Number" : 1234
    };
    
    // Convert object to JSON string
    var json  = JSON.stringify(object);
    
    // Format indent and line breaks in JSON
    var pretty = JSON.format(json);
    
    // Remove empty lines
    var html = pretty.replace(chr(13), "");
    
    // Write HTML to output
    write(html);
}#