jsonc
© 2019, Onur Yıldırım (@onury). MIT License.
Everything you need in JSON land.
npm i jsonc
Features
- Parse JSON with comments.
- Stringify objects with circular references.
- Safely parse / stringify without try/catch blocks.
- Read and auto-parse JSON files gracefully, sync or async (with promises).
- Auto-stringify and write JSON files gracefully, sync or async (with promises).
- Strips UTF-8 BOM.
- Log objects as JSON (without worrying about errors).
- Uglify/beautify JSON strings.
- More helpful JSON errors.
- Friendly API.
- TypeScript support.
Usage
See the concise API reference.
const jsonc = ;// or;
This is safe for JSON with comments:
jsonc; // » { data: 'value' }
And this is safe for circular references:
const obj = x: 1 ;objy = obj; // circularjsonc; // » { x: 1, y: '[Circular]' }
But this is seriously safe:
// safe version of every methodconst jsonc = safe;// or; const err result = jsonc;if err console; else console;
Documentation
See the concise API reference.
Change Log
-
v2.0.0 (2019-06-17)
- Requires Node.js v8 or newer.
- Updated dependencies.
-
v1.1.0 (2018-11-22)
- Fixed an issue where TypeScript compiler would complain about
'declare' modifier
. - Improved typings for safe methods.
- Updated core dependencies.
- Fixed an issue where TypeScript compiler would complain about
-
v1.0.0 (2018-10-18)
- Initial release.
License
MIT.