# jsonc

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

Latest version **2.0.0** (published 2019-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonc
pnpm add jsonc
yarn add jsonc
bun add jsonc
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-06-17 |
| First published | 2012-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 6 |
| Unpacked size | 88.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 44 |
| Author | Onur Yıldırım |
| Maintainers | onury |
| Keywords | json, object, notation, safe, stringify, parse, read-file, write-file, comments, circular, cyclic, console, log, uglify, beautify, typescript |

## Links

- npm: https://www.npmjs.com/package/jsonc
- Repository: https://github.com/onury/jsonc
- Homepage: https://onury.io/jsonc
- Issues: https://github.com/onury/jsonc/issues
- npm.io page: https://npm.io/package/jsonc

## Dependencies (6)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [strip-bom](https://npm.io/package/strip-bom.md) ^4.0.0
- [parse-json](https://npm.io/package/parse-json.md) ^4.0.0
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.15
- [fast-safe-stringify](https://npm.io/package/fast-safe-stringify.md) ^2.0.6
- [strip-json-comments](https://npm.io/package/strip-json-comments.md) ^3.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0 (latest) — 2019-06-17
- 1.1.0 — 2018-11-22
- 1.0.0 — 2018-10-18
- 0.1.0 — 2013-01-23
- 0.0.0 — 2012-08-24

## README

# jsonc

[![build-status](https://img.shields.io/travis/onury/jsonc.svg?branch=master&style=flat-square)](https://travis-ci.org/onury/jsonc)
[![coverage-status](https://img.shields.io/coveralls/github/onury/jsonc/master.svg?style=flat-square)](https://coveralls.io/github/onury/jsonc?branch=master)
[![npm](http://img.shields.io/npm/v/jsonc.svg?style=flat-square)](https://www.npmjs.com/package/jsonc)
[![release](https://img.shields.io/github/release/onury/jsonc.svg?style=flat-square)](https://github.com/onury/jsonc)
[![dependencies](https://david-dm.org/onury/jsonc.svg?style=flat-square)](https://david-dm.org/onury/jsonc)
[![license](http://img.shields.io/npm/l/jsonc.svg?style=flat-square)](https://github.com/onury/jsonc/blob/master/LICENSE)
[![maintained](https://img.shields.io/maintenance/yes/2019.svg?style=flat-square)](https://github.com/onury/jsonc/graphs/punch-card)  

> © 2019, Onur Yıldırım ([@onury](https://github.com/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][docs-api].

```js
const jsonc = require('jsonc');
// or
import { jsonc } from 'jsonc';
```

This is safe for JSON with comments:
```js
jsonc.parse('// comment\n{"data": /* comment */ "value"}\n'); // » { data: 'value' }
```

And this is safe for circular references:
```js
const obj = { x: 1 };
obj.y = obj; // circular
jsonc.stringify(obj); // » { x: 1, y: '[Circular]' }
```

But this is seriously safe:
```js
// 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][docs-api].

## 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.


[docs-api]:https://onury.io/jsonc/api
[strip-json-comments]:https://github.com/sindresorhus/strip-json-comments
[json-stringify-safe]:https://github.com/isaacs/json-stringify-safe
[parse-json]:https://github.com/sindresorhus/parse-json
[fs-extra]:https://www.npmjs.com/package/fs-extra

---
_Source: https://npm.io/package/jsonc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
