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

0.3.0 • Public • Published

JSONC reader for TypeScript

test status Code Coverage 0 dependencies install size

This micro-library (no dependencies) allows reading JSON that contain comments (JSONC). It does that by overwriting comments with whitespace - so that line and column numbers remain the same - and then loading the data as normal JSON.

import * as jsonc from "jsonc-reader"

// load JSONC from a file
const config = await jsonc.load("../my-config.jsonc")

// parse a JSONC string
const jsoncText = `
{
  // a comment
  "one": 1  // another comment
}`
const config = jsonc.parse(jsoncText)
// config === { one: 1 }

// strip comments from a JSONC string
const jsonText = jsonc.strip(jsoncText)
// jsonText === `
// {
//
//   "one": 1
// }`

/jsonc-reader/

    Package Sidebar

    Install

    npm i jsonc-reader

    Weekly Downloads

    124

    Version

    0.3.0

    License

    ISC

    Unpacked Size

    5.27 kB

    Total Files

    4

    Last publish

    Collaborators

    • kevingoslar