0.2.0 • Published 2 months ago
jsonc-reader v0.2.0
JSONC reader for TypeScript
This micro-library (no dependencies) allows reading JSON that contain comments (JSONC). It does that by stripping comments 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
// }`