{"id":13447400,"url":"https://github.com/lydell/json-stringify-pretty-compact","last_synced_at":"2025-05-15T10:01:54.552Z","repository":{"id":22703807,"uuid":"26047817","full_name":"lydell/json-stringify-pretty-compact","owner":"lydell","description":"The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`.","archived":false,"fork":false,"pushed_at":"2024-07-19T13:13:23.000Z","size":366,"stargazers_count":252,"open_issues_count":0,"forks_count":32,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-29T21:24:44.868Z","etag":null,"topics":["json","stringify"],"latest_commit_sha":null,"homepage":"https://lydell.github.io/json-stringify-pretty-compact/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lydell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-01T10:28:35.000Z","updated_at":"2024-10-24T04:44:25.000Z","dependencies_parsed_at":"2024-06-18T12:27:18.927Z","dependency_job_id":"471eabcb-ccce-4862-a47c-6c893a57e0cd","html_url":"https://github.com/lydell/json-stringify-pretty-compact","commit_stats":{"total_commits":65,"total_committers":5,"mean_commits":13.0,"dds":0.2615384615384615,"last_synced_commit":"254283ae60e693e87e39dff5881003f547bb1be7"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lydell%2Fjson-stringify-pretty-compact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lydell%2Fjson-stringify-pretty-compact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lydell%2Fjson-stringify-pretty-compact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lydell%2Fjson-stringify-pretty-compact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lydell","download_url":"https://codeload.github.com/lydell/json-stringify-pretty-compact/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319715,"owners_count":22051072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","stringify"],"created_at":"2024-07-31T05:01:16.538Z","updated_at":"2025-05-15T10:01:53.310Z","avatar_url":"https://github.com/lydell.png","language":"JavaScript","readme":"# json-stringify-pretty-compact\n\nThe output of [JSON.stringify] comes in two flavors: _compact_ and _pretty._ The former is usually too compact to be read by humans, while the latter sometimes is too spacious. This module trades performance for a compromise between the two. The result is a _pretty_ compact string, where “pretty” means both “kind of” and “nice”.\n\n\u003c!-- prettier-ignore --\u003e\n```json\n{\n  \"bool\": true,\n  \"short array\": [1, 2, 3],\n  \"long array\": [\n    {\"x\": 1, \"y\": 2},\n    {\"x\": 2, \"y\": 1},\n    {\"x\": 1, \"y\": 1},\n    {\"x\": 2, \"y\": 2}\n  ]\n}\n```\n\nWhile the “pretty” mode of [JSON.stringify] puts every item of arrays and objects on its own line, this module puts the whole array or object on a single line, unless the line becomes too long (the default maximum is 80 characters). Making arrays and objects multi-line is the only attempt made to enforce the maximum line length; if that doesn’t help then so be it.\n\n## Installation\n\n```\nnpm install json-stringify-pretty-compact\n```\n\n```js\nimport stringify from \"json-stringify-pretty-compact\";\n```\n\n\u003e **Note:** This is an [ESM only package]. (I haven’t written that gist, but it’s a great resource.)\n\u003e\n\u003e If you need CommonJS, install version 3.0.0. You won’t be missing out on anything: This package is _done._ No more features will be added, and no bugs have been found in years.\n\n**Want a CLI?** Check out [avantgardnerio/json-stringify-pretty-compact-cli]!\n\n**Web version?** Check out the [online demo]!\n\n## `stringify(obj, options = {})`\n\nIt’s like `JSON.stringify(obj, options.replacer, options.indent)`, except that objects and arrays are on one line if they fit (according to `options.maxLength`).\n\n`options`:\n\n- indent: Defaults to 2. Works exactly like the third parameter of [JSON.stringify].\n- maxLength: Defaults to 80. Lines will be tried to be kept at maximum this many characters long.\n- replacer: Defaults to undefined. Works exactly like the second parameter of [JSON.stringify].\n\n`stringify(obj, {maxLength: 0, indent: indent})` gives the exact same result as `JSON.stringify(obj, null, indent)`. (However, if you use a `replacer`, integer keys might be moved first.)\n\n`stringify(obj, {maxLength: Infinity})` gives the exact same result as `JSON.stringify(obj)`, except that there are spaces after colons and commas.\n\n**Want more options?** Check out [@aitodotai/json-stringify-pretty-compact]!\n\n## License\n\n[MIT](LICENSE).\n\n[@aitodotai/json-stringify-pretty-compact]: https://www.npmjs.com/package/@aitodotai/json-stringify-pretty-compact\n[avantgardnerio/json-stringify-pretty-compact-cli]: https://github.com/avantgardnerio/json-stringify-pretty-compact-cli\n[esm only package]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[json.stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify\n[online demo]: https://lydell.github.io/json-stringify-pretty-compact/\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flydell%2Fjson-stringify-pretty-compact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flydell%2Fjson-stringify-pretty-compact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flydell%2Fjson-stringify-pretty-compact/lists"}