Socket
Socket
Sign inDemoInstall

format-json

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    format-json

A JSON formatter module for various text/plain serialization styles


Version published
Maintainers
1
Install size
5.55 kB
Created

Readme

Source

format-json

A JSON formatter module for various text/plain serialization styles

> var json = require('format-json');
> var data = {test: "for example", some: [{nested:0, things: []}, {}]};
> console.log(json.diffy(data));
{ "test": "for example"
, "some":
  [ { "nested": 0
    , "things": []
    }
  , {}
  ]
}
> console.log(json.plain(data));
{
  "test": "for example",
  "some": [
    {
      "nested": 0,
      "things": []
    },
    {}
  ]
}
> console.log(json.terse(data));
{"test":"for example","some":[{"nested":0,"things":[]},{}]}
> console.log(json.space(data));
{ "test": "for example", "some": [ { "nested": 0, "things": [] }, {} ] }
> console.log(json.lines(data));
{ "test": "for example"
, "some": [ { "nested": 0, "things": [] }, {} ]
}

Why?

For short: diffs in version controlled JSON is what prompted json.diffy.

The comma-first style may look wonky at first, but it's a compromise that helps produce diffs where a change (addition, change or deletion) of one property has no affect on surrounding lines to reduce the amount of diff noise.

Having used this format for a while now, I also appreciate how you get straight left margins for Objects and Arrays alike.

Not convinced? Then please don't use it! :-)

FAQs

Last updated on 29 Dec 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc