jsonc-parse
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

jsonc-parse

npm version npm downloads jsr version

✨ Features

  • ESM Support
  • Tree Shakeable
  • Lightweight

📦 Installation

npm install jsonc-parse

📚 Usage

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.

import { strip } from "jsonc-parse/strip";

// or
import { strip } from "jsonc-parse";

const json = strip(`{
  "bar": "foo",
  // This is a comment.
  "foo": /* This is also a comment */ "bar",
}`);
JSON.parse(strip(json)); // { bar: "foo", foo: "bar" }

📄 License

Published under MIT License.

Package Sidebar

Install

npm i jsonc-parse

Weekly Downloads

72

Version

1.5.1

License

MIT

Unpacked Size

8.73 kB

Total Files

12

Last publish

Collaborators

  • luxass