strip-json-comments

  • Version 4.0.0
  • Published
  • 7.02 kB
  • No dependencies
  • MIT license

Install

npm i strip-json-comments
yarn add strip-json-comments
pnpm add strip-json-comments

Overview

Strip comments from JSON. Lets you use comments in your JSON files!

Index

Functions

function stripJsonComments

stripJsonComments: (jsonString: string, options?: Options) => string;
  • Strip comments from JSON. Lets you use comments in your JSON files!

    It will replace single-line comments // and multi-line comments /**\/ with whitespace. This allows JSON error positions to remain as close as possible to the original source.

    Parameter jsonString

    Accepts a string with JSON.

    Returns

    A JSON string without comments.

    Example 1

    import stripJsonComments from 'strip-json-comments';
    const json = `{
    // Rainbows
    "unicorn": "cake"
    }`;
    JSON.parse(stripJsonComments(json));
    //=> {unicorn: 'cake'}

Interfaces

interface Options

interface Options {}

    property whitespace

    readonly whitespace?: boolean;
    • Replace comments with whitespace instead of stripping them entirely.

      true

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (4)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/strip-json-comments.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/strip-json-comments)
    • HTML
      <a href="https://www.jsdocs.io/package/strip-json-comments"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>