jsonablizeΒΆ

JSONablize (qurry.capsule.jsonablize)

qurry.capsule.jsonablize.key_parse(k: Any) str | int | float | bool | None[source]ΒΆ

Make key json-allowable. If a value is not allowed by json, them return its β€˜__str__’.

str, int, float, bool or None

Parameters:

o (any) – Key.

Returns:

Json-allowable key.

Return type:

any

qurry.capsule.jsonablize.parse(o: Any) Any[source]ΒΆ

Make a python object json-allowable.

Parameters:

o (any) – Python object.

Returns:

Json-allowable python object.

Return type:

any

qurry.capsule.jsonablize.quickJSON(content: Iterable, filename: str | Path, mode: str, indent: int = 2, encoding: str = 'utf-8', jsonable: bool = False, save_location: Path | str = PosixPath('.'), mute: bool = True) str | None[source]ΒΆ

Configurable quick JSON export.

Parameters:
  • content (any) – Content wants to be written.

  • filename (str) – Filename of the file.

  • mode (str) – Mode for open() function.

  • indent (int, optional) – Indent length for json. Defaults to 2.

  • encoding (str, optional) – Encoding method. Defaults to β€˜utf-8’.

  • jsonablize (bool, optional) – Whether to transpile all object to jsonable via mori.jsonablize(). Defaults to False.

  • save_location (Union[Path, str], optional) – Location of files. Defaults to Path(β€˜./’).

  • mute (bool, optional) – Mute the exportation. Defaults to True.

Returns:

The filename of the file when not mute.

Return type:

Optional[str]

qurry.capsule.jsonablize.sort_hashable_ahead(o: dict) dict[source]ΒΆ

Make hashable values be the ahead in dictionary.”

Parameters:

o (dict) – Unsorted dictionary.

Returns:

Sorted dictionary.

Return type:

dict

qurry.capsule.jsonablize.value_parse(v: Any) Iterable | str | int | float | bool | None[source]ΒΆ

Make value json-allowable. If a value is not allowed by json, them return its β€˜__str__’.

Parameters:

v (any) – Value.

Returns:

Json-allowable value.

Return type:

any