JavaScript library for prettifying JSON in a compact, more human-readable way.
yarn add @lancejpollard/pretty-compact-json.js
const prettify1 = require("@lancejpollard/pretty-compact-json.js/1");
const prettify2 = require("@lancejpollard/pretty-compact-json.js/2");
Given this input:
{
"a": [
{
"name": "foo",
"value": 123
}
],
"b": {
"x": [1, 2, 3],
"y": {
"z": 10
},
"w": {
"a": {
"b": {
"c": 456,
"d": 789,
"e": "hello world",
"f": { "g": true, "p": [1, { "q": 2, "v": "bar" }, 3] }
}
}
}
},
"c": [{ "a": { "b": 111, "c": 222 } }, 1, null, { "x": 3 }],
"d": "random"
}
prettify1(input);
{
"a": [
{
"name": "foo",
"value": 123 } ],
"b": {
"x": [ 1, 2, 3 ],
"y": {
"z": 10 },
"w": {
"a": {
"b": {
"c": 456,
"d": 789,
"e": "hello world",
"f": {
"g": true,
"p": [
1,
{
"q": 2,
"v": "bar" },
3 ] } } } } },
"c": [
{
"a": {
"b": 111,
"c": 222 } },
1,
null,
{
"x": 3 } ],
"d": "random" }
prettify2(input)
{ "a": [ { "name": "foo",
"value": 123 } ],
"b": { "x": [ 1, 2, 3 ],
"y": { "z": 10 },
"w": { "a": { "b": { "c": 456,
"d": 789,
"e": "hello world",
"f": { "g": true,
"p": [ 1,
{ "q": 2,
"v": "bar" },
3 ] } } } } },
"c": [ { "a": { "b": 111,
"c": 222 } },
1,
null,
{ "x": 3 } ],
"d": "random" }