tiny-jsonc
An absurdly small JSONC parser.
Last updated 2 years ago by fabiospampinato .
Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install tiny-jsonc 
SYNC missed versions from official npm registry.

Tiny JSONC

An absurdly small JSONC parser.

This library works simply by using regexs to strip out comments first and trailing commas second, in order to account for a trailing comma followed by a comment, and then just passing the output to JSON.parse.

If you need additional APIs to manipulate JSONC, better error messages, or a full-blown parser, I'd recommend using json-simple-parser instead.

Install

npm install --save tiny-jsonc

Usage

import JSONC from 'tiny-jsonc';

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`

License

MIT © Fabio Spampinato

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

2 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (10)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |