Skip to content

yggdrasil.pickle.json

json

loads

loads(
    s: str | bytes | bytearray | memoryview,
    *,
    encoding: str = ...,
    errors: str = ...,
    safe: bool = ...
) -> Any
loads(
    s: str | bytes | bytearray | memoryview,
    *,
    encoding: str = "utf-8",
    errors: str = "strict",
    safe: bool = True
) -> Any

Parse JSON from s.

safe=True: Parse JSON only. No post-processing.

safe=False: Parse JSON, then recursively try to restore richer Python types from string values such as datetime/date/time/UUID.

dumps

dumps(
    obj: Any,
    *,
    encoding: str | None = ...,
    errors: str = ...,
    ensure_ascii: bool = ...,
    sort_keys: bool = ...,
    indent: int | None = ...,
    separators: tuple[str, str] | None = ...,
    safe: bool = ...,
    to_bytes: bool = True
) -> bytes
dumps(
    obj: Any,
    *,
    encoding: str | None = ...,
    errors: str = ...,
    ensure_ascii: bool = ...,
    sort_keys: bool = ...,
    indent: int | None = ...,
    separators: tuple[str, str] | None = ...,
    safe: bool = ...,
    to_bytes: bool = False
) -> str
dumps(
    obj: Any,
    *,
    encoding: str | None = "utf-8",
    errors: str = "strict",
    ensure_ascii: bool = False,
    sort_keys: bool = False,
    indent: int | None = None,
    separators: tuple[str, str] | None = None,
    safe: bool = True,
    to_bytes: bool = True
) -> bytes | str

Serialize obj to JSON.

safe=True: Conservative mode. No recursive pre-normalization. Uses stdlib JSON semantics and a narrow default hook for leaf values only.

safe=False: Broad compatibility mode. Recursively normalizes nested mappings, keys, sequences, bytes-like objects, and miscellaneous Python objects.

load

load(
    fp: IO[Any],
    *,
    encoding: str = "utf-8",
    errors: str = "strict",
    safe: bool = True
) -> Any

Read and parse JSON from a file-like object.

dump

dump(
    obj: Any,
    fp: IO[Any],
    *,
    encoding: str = "utf-8",
    errors: str = "strict",
    ensure_ascii: bool = False,
    sort_keys: bool = False,
    indent: int | None = None,
    separators: tuple[str, str] | None = None,
    safe: bool = True
) -> None

Serialize obj to JSON and write it to a file-like object.