Prettify supports beautification of JSON structures. The exposed rules are forwarded to the script
lexer for handling. Below is the different styles that can be produced with the available formatting options.
{
json: {
arrayFormat: 'default',
braceAllman: false,
bracePadding: false,
braceNewline: false,
objectIndent: false,
objectSort: false
}
}
The arrayFormat
rule controls how arrays on objects are formatted. This rules will determines if all array indexes should be indented, never indented, or left to the default.
This defaults to default
, ie: left intact and format according to the input style.
{
json: {
arrayFormat?: 'default' | 'indent' | 'inline';
}
}
{
"array": [ 1, 2,
3,
4,
5 ]
}
{
"array": [
1,
2,
3,
4,
5
]
}
{
"array": [ 1, 2, 3, 4, 5 ]
}
The braceAllman
rule puts JSON braces onto new lines, producing an Allman Style output.
This defaults to false
, ie: disabled.
{
json: {
braceAllman?: boolean;
}
}
[
{ "prop": "value" },
{ "prop": "value" },
{ "prop": "value" }
]
[
{
"prop": "value"
},
{
"prop": "value"
},
{
"prop": "value"
}
]
The bracePadding
rule applies additional spacing to structures.
This defaults to false
, ie: disabled.
{
json: {
bracePadding?:: boolean;
}
}
[
{"prop": "value"},
{"prop": "value"},
{"prop": "value"}
]
[
{ "prop": "value" },
{ "prop": "value" },
{ "prop": "value" }
]
The braceNewline
rule will insert newlines at the top and bottom of nested properties.
This defaults to false
, ie: disabled.
{
json: {
braceNewline?: boolean;
}
}
{
"one": {
"xx": {
"xx": false
}
},
"two": {
"xx": {
"xx": false
}
}
}
{
"one": {
"xx": {
"xx": false
}
},
"two": {
"xx": {
"xx": false
}
}
}
The objectSort
rule will control how object keys should be handled. You can apply indented, never indented, or left to the default. Typically, you will want to leave this option to the default to prevent unreadable objects.
This defaults to false
, ie: disabled.
{
json: {
objectSort?:: 'default' | 'indent' | 'inline'
}
}
{
"foo": {
"bar": { "bax": true }
}
}
{
"foo": {
"bar": {
"bax": true
}
}
}
{
"foo": { "bar": { "bax": true } }
}
The objectSort
rules will alphanumerically sort object properties.
This defaults to false
, ie: disabled.
{
json: {
objectSort?:: boolean;
}
}
{
"e": "5",
"b": "2",
"d": "4",
"a": "1",
"f": "6",
"c": "3"
}
{
"a": "1",
"b": "2",
"c": "3",
"d": "4",
"e": "5",
"f": "6"
}