luxass / jsonc-parse

A lightweight JSON with Comments parser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsonc-parse

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

About

A lightweight JSON with Comments parser.

License:MIT License


Languages

Language:TypeScript 97.9%Language:JavaScript 2.1%