json_dump

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

Write a collection of COMPAS object data to a JSON file.

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

  • fp (path string or file-like object) – A writeable file-like object or the path to a file.

  • pretty (bool, optional) – True to format the output with indentation, otherwise False.

Returns

None

Examples

>>> import compas
>>> from compas.geometry import Point, Vector
>>> data1 = [Point(0, 0, 0), Vector(0, 0, 0)]
>>> compas.json_dump(data1, 'data.json')
>>> data2 = compas.json_load('data.json')
>>> data1 == data2
True