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

jsonc

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonc

Everything you need in JSON land. Parse JSON with comments, stringify objects with circular references, etc...

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
88K
decreased by-8.64%
Maintainers
1
Weekly downloads
 
Created
Source

jsonc

build-status coverage-status npm release dependencies license maintained

© 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 = require('jsonc');
// or
import { jsonc } from 'jsonc';

This is safe for JSON with comments:

jsonc.parse('// comment\n{"data": /* comment */ "value"}\n'); // » { data: 'value' }

And this is safe for circular references:

const obj = { x: 1 };
obj.y = obj; // circular
jsonc.stringify(obj); // » { x: 1, y: '[Circular]' }

But this is seriously safe:

// safe version of every method
const jsonc = require('jsonc').safe;
// or
import { safe as jsonc } from 'jsonc';

const [err, result] = jsonc.parse('[invalid JSON}');
if (err) {
    console.log(`Failed to parse JSON: ${err.message}`);
} else {
    console.log(result);
}

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.
  • v1.0.0 (2018-10-18)

    • Initial release.

License

MIT.

Keywords

FAQs

Package last updated on 17 Jun 2019

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