This package has been deprecated

Author message:

No longer being worked on, please use another package.

@spacingbat3/jsonc-parser
TypeScript icon, indicating that this package has built-in type declarations

3.1.1 • Public • Published

JSONC Parser

A simple module to parse JSON with comments files with the magic of RegExp.

It allows for the specifying your own comments RegExp's as I couldn't found any information about JSONC being standarized (so for instance, if your JSONC file has single-line comments starting with hashtag, you can include that as an additional rule as well).

Usage

CommonJS

const JSONC = require('@spacingbat3/jsonc-parser').default

const parsedObject = JSONC.parse('file.jsonc')

console.log(parsedObject) // e.g. { "foo": "bar" }

ESM / TypeScript

import JSONC from '@spacingbat3/jsonc-parser'

/* NOTE: `pasedObject` is of the unknown type! */
const parsedObject = JSONC.parse('file.jsonc')

console.log(parsedObject) // e.g. { "foo": "bar" }

Custom comments formats

By the default, jsonc-parser only accepts the comments that are valid for the regular JavaScript files, but if you want to parse the other comments formats, you may specify them as shown below:

import JSONC from '@spacingbat3/jsonc-parser'

/* 
 * Removes the JavaScript-like comments and `sh`-like comments
 * (e.g. `{ "foo": "bar" # comment }`).
 */
const parsedObject = JSONC.parse('file.jsonc', /#.*/g)

console.log(parsedObject) // e.g. { "foo": "bar" }

Readme

Keywords

Package Sidebar

Install

npm i @spacingbat3/jsonc-parser

Weekly Downloads

3

Version

3.1.1

License

MIT

Unpacked Size

10.6 kB

Total Files

11

Last publish

Collaborators

  • spacingbat3