2.0.0 • Published 5 years ago

jsonc v2.0.0

Weekly downloads
12,865
License
MIT
Repository
github
Last release
5 years ago

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.

edgeos-winparali@infinitebrahmanuniverse/nolb-jsonc@everything-registry/sub-chunk-1987@digitalzz/lowcode-code-generator@fortanetwork/forta-botpumble-cliquick-transrao-lowcode-code-generator-1qik-clisalt-nodejscuvp-lowcode-code-generatortomonopnx-jsrename-toolsy-code-generatorts-docfluxteneturautemtexasservertsconfig-filesspellchecker-cliups-bot-utils@ocli/core@seada/lowcode-code-generator@scullyio/scullyebe@evanaj/lowcode-code-generator@epicgames-ps/lib-pixelstreamingsignalling-ue5.5@fcallem/create-typescript-project@istics/commander@jiankeyihao/lowcode-code-generator@mollbe/theme-compilervite-plugin-jsonxvitis-lowcode-code-generatorvtexy@herodevs/coulson@hadeshe93/flowwintt@dslc/lowcode-code-generator@digiforce-cloud/dvd-code-generatorzhixin-clizhixin-cli-toolvvlad1973-telegram-frameworkvvlad1973-utilszz-lowcode-code-generator@das.laboratory/vscode-config-interactive@cyrilis/code-generatoryves@flowaccount/scullyio-scully@omareloui/gf@ombro/h5plus@onefu/lowcode-code-generator-pages@markuplint/file-resolver@mengti/code-generatorepro-code-generatorforta-agentleeyw-lowcode-code-generator@stevecgc/lowcode-code-generator@rokkett/sveltekit-i18n@twinistics/heuristics-commander@ton1517/suppress-biome-errors@twinistics/istics-commanderlowcode-plugin-code-generator-ccslowcode-code-generator-ccslowcode-code-generator-multi@alilc/lowcode-code-generatorly-lowcode-code-generator@alexa-skill-components/catalog-explorerja-environment@abineo/sveltekit-i18ngate-lowcode-code-generatorgate-lowcode-code-generator-2merge-json-configsbc-vscode-wordsbc-minecraft-bedrock-projectbc-minecraft-bedrock-diagnoser@backtrace-labs/javascript-cli@backtrace/javascript-climockisshilary-test-lowcode-code-generatorbluedot-generator-umi4@beeman/scullyimmunx-agenticloud-photos-syncmr-json@bernales95/scullymintablenabetex2svg-nodecgserver@commitlint/config-rush-scopes@configuration-parsing/parser-jsonc@cphayim/plus
2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago

0.1.0

11 years ago

0.0.0

12 years ago