to_json#

k3d.helpers.to_json(name: str, input: Any, obj: Any | None = None, compression_level: int = 0) Any[source]#

Return JSON object serialization.

Parameters:
  • name (str) – Name of the property.

  • input (Any) – Input data to serialize.

  • obj (Any, optional) – Object containing property, by default None.

  • compression_level (int, optional) – Compression level, by default 0.

Returns:

Serialized JSON object.

Return type:

Any

Note

This function is used along with the ipywidgets package, which provides custom object serializations.

See ipywidgets documentation for more informations.

Examples#

# Example from helpers.array_serialization_wrap

def array_serialization_wrap(name):
return {
    "to_json": (lambda input, obj: to_json(name, input, obj)),
    "from_json": from_json,
}