DataDecoder
- 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
compas.data.Data
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"]
; andthe imported class has a method
from_data
.
See also
Examples
Explicit use case.
>>> import json >>> import compas >>> from compas.data import DataDecoder >>> with open(compas.get('point.json'), 'r') as f: ... point = json.load(f, cls=DataDecoder) ...
Implicit use case.
>>> from compas.data import json_load >>> point = json_load(compas.get('point.json'))
Methods
Reconstruct a deserialized object.
Inherited Methods
Return the Python representation of
s
(astr
instance containing a JSON document).Decode a JSON document from
s
(astr
beginning with a JSON document) and return a 2-tuple of the Python representation and the index ins
where the document ended.