Skip to content

octoprint.util.json.serializing#

SerializableJsonEncoding #

Bases: JsonEncoding

A JSON encoding that can serialize and deserialize objects, including additional

objects otherwise not serializable by the standard JSON encoder
  • bytes
  • frozendict.frozendict
  • datetime.datetime
  • time.struct_time

decode(dct) classmethod #

Recursively replace all instances of decodable types with their decoded values.

You'll want to have used class_encode() in your encoder to get this to work properly.

encode(val) classmethod #

Recursively replace all instances of encodable types with their encoded value. This is useful over the default= functionality of the JSON encoder because JSON will not call default for tuples, lists, ints, etc: https://docs.python.org/3/library/json.html#json.JSONEncoder

Cannot handle circular references.

class_encode(name, *params) #

Encode a class name and parameters into a serializable dict. You'll probably want to use this if you're going to set a custom decoder.

This stores the class names in a format inspired by the JSON-RPC spec at https://www.jsonrpc.org/specification_v1#a3.JSONClasshinting

Back to top