• Version 5.0.1
  • Published
  • 8 kB
  • No dependencies
  • MIT license


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


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



Type Aliases


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.


    A JSON string without comments.

    Example 1

    import stripJsonComments from 'strip-json-comments';
    const json = `{
    // Rainbows
    "unicorn": "cake"
    //=> {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.


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

    You may also use to create a custom badge linking to

    • Markdown
    • HTML
      <a href=""><img src="" alt=""></a>