@kayahr/jsonc
    Preparing search index...

    Class JSONC

    JSON-compatible parser and comment stripper.

    Index
    • Parses JSON with line and block comments.

      Comments are replaced with whitespace before the native JSON.parse is called, retaining their exact source offsets in parse errors. The optional reviver is passed through unchanged.

      Parameters

      • text: string

        JSONC source text to parse.

      • Optionalreviver: (this: any, key: string, value: any) => any

        Optional native JSON reviver.

      Returns any

      Parsed JSON value.

      SyntaxError - When the source text is not valid JSONC.

    • Removes line and block comments from JSONC source text.

      Clean mode removes comment-only lines and preceding horizontal whitespace. Preserve mode replaces comment characters with spaces while retaining the exact length and line-break offsets of the source text.

      Parameters

      • text: string

        JSONC source text.

      • mode: JSONCStripMode = "clean"

        Comment removal mode. Defaults to "clean".

      Returns string

      Strict JSON source text if the input was otherwise valid JSON.

      SyntaxError - When a block comment is not terminated.