A lightweight JSON with Comments parser.
npm install jsonc-parse[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![jsr version][jsr-version-src]][jsr-version-href]
- ESM Support
- Tree Shakeable
- Lightweight
``sh`
npm install jsonc-parse
`ts
import { parse, parseFile, parseFileSync } from "jsonc-parse";
// From file async
const jsonCFile = await parseFile("./config.jsonc");
// From file
const jsonCFile = parseFileSync("./config.jsonc");
// From string
const jsonC = parse({
"bar": "foo",
// This is a comment.
"foo": / This is also a comment / "bar",
});`
you can also just import the strip function to remove comments from a string.
`ts
// or
import { strip } from "jsonc-parse";
import { strip } from "jsonc-parse/strip";
const json = strip({
"bar": "foo",
// This is a comment.
"foo": / This is also a comment / "bar",
});``
JSON.parse(strip(json)); // { bar: "foo", foo: "bar" }
Published under MIT License.
[npm-version-src]: https://img.shields.io/npm/v/jsonc-parse?style=flat&colorA=18181B&colorB=4169E1
[npm-version-href]: https://npmjs.com/package/jsonc-parse
[npm-downloads-src]: https://img.shields.io/npm/dm/jsonc-parse?style=flat&colorA=18181B&colorB=4169E1
[npm-downloads-href]: https://npmjs.com/package/jsonc-parse
[jsr-version-src]: https://jsr.io/badges/@luxass/jsonc-parse?style=flat&labelColor=18181B&logoColor=4169E1
[jsr-version-href]: https://jsr.io/@luxass/jsonc-parse