class compas.utilities.DataDecoder(*args, **kwargs)[source]

Bases: JSONDecoder

Data decoder for custom JSON serialization with support for COMPAS data structures and geometric primitives.

The decoder hooks into the JSON deserialisation process to reconstruct objects, such as geometric primitives and shapes, data structures, robots, …, from the serialized data when possible.

The reconstruction is possible if

  • the serialized data has the following structure: {"dtype": "...", 'value': {...}};

  • a class can be imported into the current scope from the info in o["dtype"]; and

  • the imported class has a method from_data.


Explicit use case.

>>> import json
>>> from import DataDecoder
>>> with open('point.json') as f:
...     point = json.load(f, cls=DataDecoder)

Implicit use case.

>>> from import json_load
>>> point = json_load('point.json')



Reconstruct a deserialized object.

Inherited Methods


Return the Python representation of s (a str instance containing a JSON document).


Decode a JSON document from s (a str beginning with a JSON document) and return a 2-tuple of the Python representation and the index in s where the document ended.