zserio.debugstring module

The module provides utilities for JSON debug string which can be obtained from zserio objects.

Note

Zserio objects must be generated with -withTypeInfoCode zserio option to enable JSON debug string!

zserio.debugstring.from_json_file(obj_class: Type[Any], filename: str, *arguments: List[Any]) Any[source]

Parses JSON debug string from given file and creates instance of the requested zserio object according to the data contained in the debug string.

Note

The created object can be only partially initialized depending on the data stored in the JSON debug string.

import zserio

obj = zserio.from_json_file(SomeZserioObject, "file_name.json")
Parameters:
  • obj_class – Class instance of the generated object to create.

  • filename – File name to read.

  • arguments – Arguments of the generated zserio object.

Returns:

Instance of the requested zserio object.

Raises:

PythonRuntimeException – In case of any error.

zserio.debugstring.from_json_stream(obj_class: Type[Any], text_io: TextIO, *arguments: List[Any]) Any[source]

Parses JSON debug string from given text stream and creates instance of the requested zserio object according to the data contained in the debug string.

Note

The created object can be only partially initialized depending on the data stored in the JSON debug string.

import io
import zserio

text_io = io.StringIO("{\"field1\": 13}")
obj = zserio.from_json_stream(SomeZserioObject, text_io)
Parameters:
  • obj_class – Class instance of the generated object to create.

  • text_io – Text stream to use.

  • arguments – Arguments of the generated zserio object.

Returns:

Instance of the requested zserio object.

Raises:

PythonRuntimeException – In case of any error.

zserio.debugstring.from_json_string(obj_class: Type[Any], json_string: str, *arguments: List[Any]) Any[source]

Parses JSON debug string and creates instance of the requested zserio object according to the data contained in the debug string.

Note

The created object can be only partially initialized depending on the data stored in the JSON debug string.

import zserio

json_string = "{\"field1\": 13}"
obj = zserio.from_json_string(SomeZserioObject, json_string)
Parameters:
  • obj_class – Class instance of the generated object to create.

  • json_string – JSON debug string to parse.

  • arguments – Arguments of the generated zserio object.

Returns:

Instance of the requested zserio object.

Raises:

PythonRuntimeException – In case of any error.

zserio.debugstring.to_json_file(obj: Any, filename: str, *, indent: None | int | str = 4, walk_filter: WalkFilter | None = None) None[source]

Writes contents of given zserio object to debug file in JSON format using Walker with JsonWriter.

Example:

import zserio

obj = SomeZserioObject()
zserio.to_json_file(obj, "file_name.json")

The function allows usage of walk filters as well. The following example shows filtering of arrays up to 5 elements:

import zserio

obj = SomeZserioObject()
walk_filter = zserio.ArrayLengthWalkFilter(5)
zserio.to_json_file(obj, "file_name.json", walk_filter=walk_filter)
Parameters:
  • obj – Zserio object to use.

  • filename – Name of file to write.

  • indent – Indent argument for JsonWriter.

  • walk_filter – Walk filter to use by Walker.

zserio.debugstring.to_json_stream(obj: Any, text_io: TextIO, *, indent: None | int | str = 4, walk_filter: WalkFilter | None = None) None[source]

Writes contents of given zserio object to debug stream in JSON format using Walker with JsonWriter.

Example:

import io
import zserio

obj = SomeZserioObject()
text_io = io.StringIO()
zserio.to_json_stream(obj, text_io)

The function allows usage of walk filters as well. The following example shows filtering of arrays up to 5 elements:

import io
import zserio

obj = SomeZserioObject()
text_io = io.StringIO()
walk_filter = zserio.ArrayLengthWalkFilter(5)
zserio.to_json_stream(obj, text_io, walk_filter=walk_filter)
Parameters:
  • obj – Zserio object to use.

  • text_io – Text stream to use.

  • indent – Indent argument for JsonWriter.

  • walk_filter – Walk filter to use by Walker.

zserio.debugstring.to_json_string(obj: Any, *, indent: None | int | str = 4, walk_filter: WalkFilter | None = None) str[source]

Gets debug string in JSON format using Walker with JsonWriter for given zserio object.

Example:

import zserio

obj = SomeZserioObject()
zserio.to_json_string(obj)

The function allows usage of walk filters as well. The following example shows filtering of arrays up to 5 elements:

import zserio

obj = SomeZserioObject()
walk_filter = zserio.ArrayLengthWalkFilter(5)
zserio.to_json_string(obj, walk_filter=walk_filter)
Parameters:
  • obj – Zserio object to use.

  • indent – Indent argument for JsonWriter.

  • walk_filter – Walk filter to use by Walker.

Returns:

JSON debug string.