All Projects → lydell → Json Stringify Pretty Compact

lydell / Json Stringify Pretty Compact

Licence: mit
The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Json Stringify Pretty Compact

Sketch I18n
Translate pages in Sketch
Stars: ✭ 173 (-2.26%)
Mutual labels:  json
Gulp Ng Config
🔧 Create AngularJS constants from a JSON config file
Stars: ✭ 176 (-0.56%)
Mutual labels:  json
Cleanjson
Swift JSON decoder for Codable
Stars: ✭ 178 (+0.56%)
Mutual labels:  json
Githubdb
A Lightweight Cloud based JSON Database with a MongoDB like API for Node.
Stars: ✭ 174 (-1.69%)
Mutual labels:  json
Qxorm
QxOrm library - C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library - Official repository
Stars: ✭ 176 (-0.56%)
Mutual labels:  json
Django Import Export
Django application and library for importing and exporting data with admin integration.
Stars: ✭ 2,265 (+1179.66%)
Mutual labels:  json
Synth
The Declarative Data Generator
Stars: ✭ 161 (-9.04%)
Mutual labels:  json
School
Sistema de gerenciamento para escola em Laravel com VueJS (Não é mais Angular)
Stars: ✭ 178 (+0.56%)
Mutual labels:  json
Emoji.json
Just an emoji.json
Stars: ✭ 175 (-1.13%)
Mutual labels:  json
Json table
Flutter package: Json Table Widget to create table from json array
Stars: ✭ 178 (+0.56%)
Mutual labels:  json
Web Database Analytics
Web scrapping and related analytics using Python tools
Stars: ✭ 175 (-1.13%)
Mutual labels:  json
Tilejson Spec
JSON format for describing map tilesets.
Stars: ✭ 175 (-1.13%)
Mutual labels:  json
Quran Json
Holy Quran with translation and tafsir in Bahasa Indonesia, presented in JSON format
Stars: ✭ 177 (+0%)
Mutual labels:  json
Json2html
🐍 Python module for converting complex JSON to HTML Table representation
Stars: ✭ 173 (-2.26%)
Mutual labels:  json
Json6
JSON for Humans (ES6)
Stars: ✭ 177 (+0%)
Mutual labels:  json
Linkedin Profile Scraper
🕵️‍♂️ LinkedIn profile scraper returning structured profile data in JSON. Works in 2020.
Stars: ✭ 171 (-3.39%)
Mutual labels:  json
Json
Strongly typed JSON library for Rust
Stars: ✭ 2,544 (+1337.29%)
Mutual labels:  json
Jackson Jq
jq for Jackson Java JSON Processor
Stars: ✭ 178 (+0.56%)
Mutual labels:  json
Boo
Boo - A beautiful, clean and responsive theme for Ghost.
Stars: ✭ 176 (-0.56%)
Mutual labels:  json
Staticjson
Fast, direct and static typed parsing of JSON with C++
Stars: ✭ 177 (+0%)
Mutual labels:  json

json-stringify-pretty-compact

The 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”.

{
  "bool": true,
  "short array": [1, 2, 3],
  "long array": [
    {"x": 1, "y": 2},
    {"x": 2, "y": 1},
    {"x": 1, "y": 1},
    {"x": 2, "y": 2}
  ]
}

While 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.

Installation

npm install json-stringify-pretty-compact
const stringify = require("json-stringify-pretty-compact");

stringify(obj, options = {})

It’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).

options:

  • indent: Defaults to 2. Works exactly like the third parameter of JSON.stringify.
  • maxLength: Defaults to 80. Lines will be tried to be kept at maximum this many characters long.
  • replacer: Defaults to undefined. Works exactly like the second parameter of JSON.stringify.

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.)

stringify(obj, {maxLength: Infinity}) gives the exact same result as JSON.stringify(obj), except that there are spaces after colons and commas.

Want more options? Check out @aitodotai/json-stringify-pretty-compact!

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].