Skip to main content
Home

Built and signed on GitHub Actions

A lightweight JSON with Comments parser.

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
4 months ago (1.5.5)

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.

// 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" }

📄 License

Published under MIT License.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@luxass/jsonc-parse

Import symbol

import * as jsonc_parse from "@luxass/jsonc-parse";
or

Import directly with a jsr specifier

import * as jsonc_parse from "jsr:@luxass/jsonc-parse";

Add Package

pnpm i jsr:@luxass/jsonc-parse
or (using pnpm 10.8 or older)
pnpm dlx jsr add @luxass/jsonc-parse

Import symbol

import * as jsonc_parse from "@luxass/jsonc-parse";

Add Package

yarn add jsr:@luxass/jsonc-parse
or (using Yarn 4.8 or older)
yarn dlx jsr add @luxass/jsonc-parse

Import symbol

import * as jsonc_parse from "@luxass/jsonc-parse";

Add Package

npx jsr add @luxass/jsonc-parse

Import symbol

import * as jsonc_parse from "@luxass/jsonc-parse";

Add Package

bunx jsr add @luxass/jsonc-parse

Import symbol

import * as jsonc_parse from "@luxass/jsonc-parse";