json_dumps

compas.data.json_dumps(data, pretty=False)[source]

Write a collection of COMPAS objects to a JSON string.

Parameters
  • data (object) – Any JSON serializable object. This includes any (combination of) COMPAS object(s).

  • pretty (bool, optional) – If True, format the output with newlines and indentation.

Returns

str

Examples

>>> import compas
>>> from compas.geometry import Point, Vector
>>> data1 = [Point(0, 0, 0), Vector(0, 0, 0)]
>>> s = compas.json_dumps(data1)
>>> data2 = compas.json_loads(s)
>>> data1 == data2
True