Skip to content

Core

Implementation of the JSON5 decoder.

JsonValue module-attribute

JsonValue = dict | list | int | float | str | None | bool

Type hint for JSON5 values.

JSON5DecodeError

JSON5DecodeError(msg: str, doc: str, pos: int)

Bases: ValueError

Subclass of ValueError with the following additional properties:

msg: The unformatted error message doc: The JSON document being parsed pos: The start index of doc where parsing failed lineno: The line corresponding to pos colno: The column corresponding to pos

Source code in src/ujson5/core.py
22
23
24
25
26
27
28
29
30
31
def __init__(self, msg: str, doc: str, pos: int) -> None:
    lineno = doc.count("\n", 0, pos) + 1
    colno = pos - doc.rfind("\n", 0, pos)
    err_msg = f"{msg}: line {lineno} column {colno} (char {pos})"
    ValueError.__init__(self, err_msg)
    self.msg = msg
    self.doc = doc
    self.pos = pos
    self.lineno = lineno
    self.colno = colno