/pretty-json

A JSON formatter based on ANTLR.

Apache License 2.0Apache-2.0

PrettyJson is a JSON formatter based on ANTLR.

##Usage

new JsonFormatter().format(JSON);
new JsonFormatter(settings).format(JSON);

##Settings

The formatter currently supports the following settings (via JsonFormatterSettings):

  • Indentation size (Default: 2)
  • No. spaces before/after a colon (Default: 1/1)
  • No. spaces before/after a comma (Default: 0/0)
  • Newline after opening/closing brace? (Default: true/true)
  • Newline after opening/closing bracket? (Default: true/true)
  • Newline after object member? (Default: true)
  • Newline after array element? (Default: true)

For example, the JSON string

{"KEY1":"VALUE1","SUBDOC":{"KEY2":"VALUE2","KEY3":[1,2,3]}}

would be formatted like this:

{
  "KEY1" : "VALUE1", // Object member
  "SUBDOC" : {
    "KEY2" : "VALUE2",
    "KEY3" : [
      1, // Array element
      2,
      3
    ]
  }
}

##Building

./gradlew clean build jarjar

JarJar is used to embed ANTLR dependencies within the JAR.