Coder Social home page Coder Social logo

jsonc's Introduction

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.

jsonc's People

Contributors

onury avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.