jschon.json

class jschon.json.JSON(value, *, parent=None, key=None, itemclass=None, **itemkwargs)

An implementation of the JSON data model.

__init__(value, *, parent=None, key=None, itemclass=None, **itemkwargs)

Initialize a JSON instance from the given JSON-compatible value.

The parent, key, itemclass and itemkwargs parameters should typically only be used in the construction of compound JSON documents by JSON subclasses.

Parameters
  • value (jschon.json.AnyJSONCompatible) – a JSON-compatible Python object

  • parent (Optional[jschon.json.JSON]) – the parent node of the instance

  • key (Optional[str]) – the index of the instance within its parent

  • itemclass (Optional[Type[jschon.json.JSON]]) – the JSON subclass used to instantiate child nodes of arrays and objects (default: JSON)

  • itemkwargs (Any) – keyword arguments to pass to the itemclass constructor

classmethod loadf(path, **kwargs)

Deserialize a JSON file to a JSON instance.

Parameters
  • path (Union[str, os.PathLike]) – the path to the file

  • kwargs (Any) – keyword arguments to pass to the JSON (subclass) constructor

Return type

jschon.json.JSON

classmethod loads(value, **kwargs)

Deserialize a JSON string to a JSON instance.

Parameters
  • value (str) – the JSON string

  • kwargs (Any) – keyword arguments to pass to the JSON (subclass) constructor

Return type

jschon.json.JSON

data: Union[None, bool, int, decimal.Decimal, str, List[jschon.json.JSON], Dict[str, jschon.json.JSON]]

The instance data.

JSON type

data type

null

None

boolean

bool

number

int | Decimal

string

str

array

list[JSON]

object

dict[str, JSON]

key: Optional[str]

The index of the instance within its parent.

parent: Optional[jschon.json.JSON]

The containing JSON instance.

property path: jschon.jsonpointer.JSONPointer

Return the path to the instance from the document root.

type: str

The JSON type of the instance. One of "null", "boolean", "number", "string", "array", "object".

property value: jschon.json.AnyJSONCompatible

Return the instance data as a JSON-compatible Python object.

jschon.json.AnyJSONCompatible

Type hint for a JSON-compatible Python object.

alias of TypeVar(‘AnyJSONCompatible’, None, bool, int, float, decimal.Decimal, str, Sequence, Mapping)