rich.json¶
- class rich.json.JSON(json, indent=2, highlight=True, skip_keys=False, ensure_ascii=False, check_circular=True, allow_nan=True, default=None, sort_keys=False)[source]¶
A renderable which pretty prints JSON.
- Parameters
json (str) – JSON encoded data.
indent (Union[None, int, str], optional) – Number of characters to indent by. Defaults to 2.
highlight (bool, optional) – Enable highlighting. Defaults to True.
skip_keys (bool, optional) – Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional) – Escape all non-ascii characters. Defaults to False.
check_circular (bool, optional) – Check for circular references. Defaults to True.
allow_nan (bool, optional) – Allow NaN and Infinity values. Defaults to True.
default (Callable, optional) – A callable that converts values that can not be encoded in to something that can be JSON encoded. Defaults to None.
sort_keys (bool, optional) – Sort dictionary keys. Defaults to False.
- classmethod from_data(data, indent=2, highlight=True, skip_keys=False, ensure_ascii=False, check_circular=True, allow_nan=True, default=None, sort_keys=False)[source]¶
Encodes a JSON object from arbitrary data.
- Parameters
data (Any) – An object that may be encoded in to JSON
indent (Union[None, int, str], optional) – Number of characters to indent by. Defaults to 2.
highlight (bool, optional) – Enable highlighting. Defaults to True.
default (Callable, optional) – Optional callable which will be called for objects that cannot be serialized. Defaults to None.
skip_keys (bool, optional) – Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional) – Escape all non-ascii characters. Defaults to False.
check_circular (bool, optional) – Check for circular references. Defaults to True.
allow_nan (bool, optional) – Allow NaN and Infinity values. Defaults to True.
default – A callable that converts values that can not be encoded in to something that can be JSON encoded. Defaults to None.
sort_keys (bool, optional) – Sort dictionary keys. Defaults to False.
- Returns
New JSON object from the given data.
- Return type