DataEncoder
- class compas.data.DataEncoder[source]
- Bases: - JSONEncoder- Data encoder for custom JSON serialization with support for COMPAS data structures and geometric primitives. - The encoder adds the following conversions to the JSON serialisation process: - Numpy objects to their Python equivalents; 
- iterables to lists; and 
- compas.data.Dataobjects, such as geometric primitives and shapes, data structures, robots, …, to a dict with the following structure:- {'dtype': o.__dtype__, 'data': o.__data__}
 - See also - Examples - Explicit use case. - >>> import json >>> from compas.data import DataEncoder >>> from compas.geometry import Point >>> point = Point(0, 0, 0) >>> with open("point.json", "w") as f: ... json.dump(point, f, cls=DataEncoder) - Implicit use case. - >>> from compas.data import json_dump >>> from compas.geometry import Point >>> point = Point(0, 0, 0) >>> json_dump(point, "point.json") - Methods - Return an object in serialized form. - Inherited Methods - Return a JSON string representation of a Python data structure. - Encode the given object and yield each string representation as available.