Skip to content

A simple reader for JSONC text and files

Notifications You must be signed in to change notification settings

kevgo/jsonc-reader-ts

Repository files navigation

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

About

A simple reader for JSONC text and files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published