New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@spacingbat3/jsonc-parser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spacingbat3/jsonc-parser

Simple JSON with Comments file parser.

latest
Source
npmnpm
Version
3.1.1
Version published
Maintainers
1
Created
Source

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

Keywords

jsonc

FAQs

Package last updated on 26 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts