Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonc-simple-parser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonc-simple-parser

A simple JSON parser that supports comments and optional trailing commas.

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.8K
decreased by-4.28%
Maintainers
1
Weekly downloads
 
Created
Source

JSONC Simple Parser

A simple JSON parser that supports comments and optional trailing commas.

Features

  • Tiny:
    • It's ~3.5kb minified and gzipped, if you aren't already using RegHex, otherwise it's just ~2kb.
    • Even if you aren't using RegHex already (you should) that's ~32% smaller than VS Code's jsonc-parser and ~62% smaller than JSON5.
  • Performant:
    • When parsing regular JSON it's ~10x faster than VS Code's jsonc-parser, ~70x faster than JSON5 and just as fast as the native JSON.parse.
    • When parsing JSON with comments or trailing commas it's just as fast as VS Code's jsonc-parser and ~6x faster than JSON5.
  • Tested:
    • It passes all 274 tests regarding JSON from ECMA's test262 test suite.
    • The parser is obviously not spec compliant but this means that while adding support for comments and trailing commas probably nothing else got broken.

Install

npm install --save jsonc-simple-parser

Usage

import JSONC from 'jsonc-simple-parser';

const source = `
  { // This is an example
    "foo": 123,
    /* TRAILING COMMAS */
    "bar": [1, 2, 3,],
  }
`;

const result = {
  foo: 123,
  bar: [1, 2, 3]
};

JSONC.parse ( source ); // => returns an object that's deeply equal to `result`
JSONC.stringify ( result ); // => same as calling `JSON.stringify`

License

MIT © Fabio Spampinato

Keywords

FAQs

Package last updated on 20 Mar 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc