jschon.json
- class jschon.json.JSON(value, *, parent=None, key=None, itemclass=None, **itemkwargs)
An implementation of the JSON data model.
- Parameters:
- __bool__()
Return bool(self).
- Return type:
bool
- __delitem__(index)
Delete self[index].
Supported for JSON types
array
andobject
.- Parameters:
index (int | str) –
- Return type:
None
- __eq__(other)
Return self == other.
- Parameters:
other (JSON | None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
bool
- __ge__(other)
Return self >= other.
Supported for JSON types
number
andstring
.- Parameters:
other (JSON | int | float | str) –
- Return type:
bool
- __getitem__(index)
Return self[index].
Supported for JSON types
array
andobject
.- Parameters:
index (int | slice | str) –
- Return type:
- __gt__(other)
Return self > other.
Supported for JSON types
number
andstring
.- Parameters:
other (JSON | int | float | str) –
- Return type:
bool
- __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 byJSON
subclasses.- Parameters:
value (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) – a JSON-compatible Python object
parent (JSON) – the parent node of the instance
key (str) – the index of the instance within its parent
itemclass (Type[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
- __iter__()
Return iter(self).
Supported for JSON types
array
andobject
.- Return type:
Iterator
- __le__(other)
Return self <= other.
Supported for JSON types
number
andstring
.- Parameters:
other (JSON | int | float | str) –
- Return type:
bool
- __len__()
Return len(self).
Supported for JSON types
string
,array
andobject
.- Return type:
int
- __lt__(other)
Return self < other.
Supported for JSON types
number
andstring
.- Parameters:
other (JSON | int | float | str) –
- Return type:
bool
- __repr__()
Return repr(self).
- Return type:
str
- __setitem__(index, obj)
Set self[index] to obj.
Supported for JSON types
array
andobject
.- Parameters:
index (int | str) –
obj (JSON | None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None
- __str__()
Return str(self).
- Return type:
str
- add(path, obj)
Add obj at path relative to self.
The
JSON
equivalent toadd()
, this method performs an in-place JSON Patchadd
operation on self.If path is empty, the value of self is replaced by obj.
Experimental.
- Parameters:
path (str | JSONPointer) –
obj (JSON | None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None
- copy(from_, to)
Not yet implemented; experimental.
- Parameters:
from_ (str | JSONPointer) –
to (str | JSONPointer) –
- Return type:
None
- dumpf(path)
Serialize the instance data to a JSON file.
- Parameters:
path (str | PathLike) – the path to the file
- Return type:
None
- dumps()
Serialize the instance data to a JSON string.
- Return type:
str
- insert(index, obj)
Insert obj before index.
Supported for JSON type
array
.- Parameters:
index (int) –
obj (JSON | None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None
- move(from_, to)
Not yet implemented; experimental.
- Parameters:
from_ (str | JSONPointer) –
to (str | JSONPointer) –
- Return type:
None
- remove(path)
Remove the instance at path relative to self.
The
JSON
equivalent toremove()
, this method performs an in-place JSON Patchremove
operation on self.If path is empty, the value of self is set to None.
Experimental.
- Parameters:
path (str | JSONPointer) –
- Return type:
None
- replace(path, obj)
Set obj at path relative to self.
The
JSON
equivalent toreplace()
, this method performs an in-place JSON Patchreplace
operation on self.If path is empty, the value of self is replaced by obj.
Experimental.
- Parameters:
path (str | JSONPointer) –
obj (JSON | None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None
- test(path, obj)
Not yet implemented; experimental.
- Parameters:
path (str | JSONPointer) –
obj (JSON | None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None
- data: None | bool | int | float | str | List[JSON] | Dict[str, JSON]
The instance data.
JSON type
data type
null
None
boolean
bool
number
int | float
string
str
array
list[JSON]
object
dict[str, JSON]
- key: str | None
The index of the instance within its parent.
- property path: 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: None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
Return the instance data as a JSON-compatible Python object.
- jschon.json.JSONCompatible
Type hint for a JSON-compatible Python object.
alias of
Union
[None
,bool
,int
,float
,str
,Sequence
[Any
],Mapping
[str
,Any
]]
- jschon.json.false = False
Use to represent the JSON false value literally in Python code.
- jschon.json.null = None
Use to represent the JSON null value literally in Python code.
- jschon.json.true = True
Use to represent the JSON true value literally in Python code.