https://github.com/gre/json-beautify
JSON.stringify with fixed maximum character width.
https://github.com/gre/json-beautify
Last synced: about 2 months ago
JSON representation
JSON.stringify with fixed maximum character width.
- Host: GitHub
- URL: https://github.com/gre/json-beautify
- Owner: gre
- Created: 2015-05-14T15:38:22.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-02-10T14:20:50.000Z (over 5 years ago)
- Last Synced: 2025-03-20T00:38:45.933Z (2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 45
- Watchers: 3
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
json-beautify
=============
JSON.stringify with fixed maximum character width.**json-beautify** is a fork of `JSON.stringify` [json2.js](https://github.com/douglascrockford/JSON-js/blob/master/json2.js) implementation.
It has the exact same signature of `JSON.stringify` but it also adds an optional 4th parameter:
The maximum fixed character width (for instance 80).
## Examples:
```js
var beautify = require("json-beautify");var obj = { str: "Hello World", num: 42, smallarray: [ 1, 2, 3, "foo", {} ], smallobject: { foo: "bar", bar: 42 }, bigarray: [ 1, 2, 3, "foo", { foo: "bar", bar: 42, arr: [ 1, 2, 3, "foo", {} ] } ], bigobject: { foo: [ 1, 2, 3, "foo", {} ], bar: 42, a: {b: { c: 42 }}, foobar: "FooBar" } };
```### With 100 fixed-spaces:
```js
console.log(beautify(obj, null, 2, 100));
``````json
{
"str": "Hello World",
"num": 42,
"smallarray": [ 1, 2, 3, "foo", {} ],
"smallobject": { "foo": "bar", "bar": 42 },
"bigarray": [ 1, 2, 3, "foo", { "foo": "bar", "bar": 42, "arr": [ 1, 2, 3, "foo", {} ] } ],
"bigobject": { "foo": [ 1, 2, 3, "foo", {} ], "bar": 42, "a": { "b": { "c": 42 } }, "foobar": "FooBar" }
}
```### With 80 fixed-spaces:
```js
console.log(beautify(obj, null, 2, 80));
``````json
{
"str": "Hello World",
"num": 42,
"smallarray": [ 1, 2, 3, "foo", {} ],
"smallobject": { "foo": "bar", "bar": 42 },
"bigarray": [
1,
2,
3,
"foo",
{ "foo": "bar", "bar": 42, "arr": [ 1, 2, 3, "foo", {} ] }
],
"bigobject": {
"foo": [ 1, 2, 3, "foo", {} ],
"bar": 42,
"a": { "b": { "c": 42 } },
"foobar": "FooBar"
}
}
```