Skip to content

JSON Formatter

Rahul Raveendran edited this page Feb 8, 2017 · 1 revision

This class can format your JSON input (String/JSONObject/JSONArray) and return a String or colored HTML version of the same.

format JSON as String.

new JsonFormatter.Builder().build().format(json);

format JSON as colored HTML

new JsonFormatter.Builder()
        .setOutputFormat(JsonFormatter.HTML)
        .build()
        .format(json);

The library is provided with a default color theme which kind of look like that of Json Parser Online. The developer can change the color theme using the Builder class's methods.

Here is an example that changes the color of keys in the JSON.

new JsonFormatter.Builder()
        .setOutputFormat(JsonFormatter.HTML)
        .setKeyColor("#00ff00")
        .build()
        .format(json);

Note: The color theme works only for the HTML output.

Clone this wiki locally