Skip to content

JSON Utilities

trulens_eval.utils.json

Json utilities and serialization utilities dealing with json.

Attributes

Classes

Functions

obj_id_of_obj

obj_id_of_obj(obj: dict, prefix='obj')

Create an id from a json-able structure/definition. Should produce the same name if definition stays the same.

json_str_of_obj

json_str_of_obj(obj: Any, *args, redact_keys: bool = False, **kwargs) -> str

Encode the given json object as a string.

json_default

json_default(obj: Any) -> str

Produce a representation of an object which does not have a json serializer.

jsonify_for_ui

jsonify_for_ui(*args, **kwargs)

Options for jsonify common to UI displays.

Redacts keys and hides special fields introduced by trulens.

jsonify

jsonify(obj: Any, dicted: Optional[Dict[int, JSON]] = None, instrument: Optional['Instrument'] = None, skip_specials: bool = False, redact_keys: bool = False, include_excluded: bool = True) -> JSON

Convert the given object into types that can be serialized in json.

PARAMETER DESCRIPTION
obj

the object to jsonify.

TYPE: Any

dicted

the mapping from addresses of already jsonifed objects (via id) to their json.

TYPE: Optional[Dict[int, JSON]] DEFAULT: None

instrument

instrumentation functions for checking whether to recur into components of obj.

TYPE: Optional['Instrument'] DEFAULT: None

skip_specials

remove specially keyed structures from the json. These have keys that start with "__tru_".

TYPE: bool DEFAULT: False

redact_keys

redact secrets from the output. Secrets are detremined by keys.py:redact_value .

TYPE: bool DEFAULT: False

include_excluded

include fields that are annotated to be excluded by pydantic.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
JSON

The jsonified version of the given object. Jsonified means that the the

JSON

object is either a JSON base type, a list, or a dict with the containing

JSON

elements of the same.