GitHub

API reference for jsonc.

JSON with comments to Python values (Effect's encoding/Jsonc), without dependencies: the JSONC draft with jsonc-parser 3.3.1's default profile, JSON plus line and block comments, no trailing commas. One leading byte order mark is skipped. Values are read as pyfect reads JSON (JSON.parse)::

jsonc.parse('{ "port": 8080 } // comment')  # Ok({"port": 8080})

Functions

parse

parse(text) -> Result[object, EncodingError]

The value of a JSONC document, or an EncodingError whose message gives the line and column (in UTF-16 code units) without quoting the text. Trailing commas and JSON5 extensions are errors.

ParameterTypeDescription
textstr

Returns Result[object, EncodingError]

def parse(text: str, /) -> Result[object, EncodingError]:
    """The value of a JSONC document, or an ``EncodingError`` whose message
    gives the line and column (in UTF-16 code units) without quoting the
    text. Trailing commas and JSON5 extensions are errors."""
    try:
        return Ok(_parse(text))
    except ValueError as error:
        return Err(EncodingError(kind="Decode", module="Jsonc", input=text, message=str(error)))