strip-json-comments

  • Version 5.0.1
  • Published
  • 8 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

Type Aliases

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

Type Aliases

type Options

type Options = {
/**
Strip trailing commas in addition to comments.
@default false
*/
readonly trailingCommas?: boolean;
/**
Replace comments and trailing commas with whitespace instead of stripping them entirely.
@default true
*/
readonly whitespace?: boolean;
};

    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>