JSPM

jsonc-simple-parser

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2975
  • Score
    100M100P100Q121218F
  • License MIT

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

Package Exports

  • jsonc-simple-parser

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsonc-simple-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JSONC Simple Parser

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

Features

  • Tiny:
    • It's ~2.1kb minified and gzipped, if you aren't already using RegHex, otherwise it's just ~.5kb.
    • Even if you aren't using RegHex already (you should) that's ~60% smaller than VS Code's jsonc-parser and ~80% 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 144 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