docarray.array.mixins.io.json module#

class docarray.array.mixins.io.json.JsonIOMixin[source]#

Bases: object

Save/load a array into a JSON file.

save_json(file, protocol='jsonschema', encoding='utf-8', **kwargs)[source]#

Save array elements into a JSON file.

Comparing to save_binary(), it is human-readable but slower to save/load and the file size larger.

Parameters:
  • file (Union[str, TextIO]) – File or filename to which the data is saved.

  • protocol (str) – jsonschema or protobuf

  • encoding (str) – encoding used to save data into a JSON file. By default, utf-8 is used.

Return type:

None

classmethod load_json(file, protocol='jsonschema', encoding='utf-8', **kwargs)[source]#

Load array elements from a JSON file.

Parameters:
  • file (Union[str, TextIO]) – File or filename or a JSON string to which the data is saved.

  • protocol (str) – jsonschema or protobuf

  • encoding (str) – encoding used to load data from a JSON file. By default, utf-8 is used.

Return type:

T

Returns:

a DocumentArrayLike object

classmethod from_json(file, protocol='jsonschema', **kwargs)[source]#
Return type:

T

classmethod from_list(values, protocol='jsonschema', **kwargs)[source]#
Return type:

T

to_list(protocol='jsonschema', **kwargs)[source]#

Convert the object into a Python list.

Parameters:

protocol (str) – jsonschema or protobuf

Return type:

List

Returns:

a Python list

to_json(protocol='jsonschema', **kwargs)[source]#

Convert the object into a JSON string. Can be loaded via load_json().

Parameters:

protocol (str) – jsonschema or protobuf

Return type:

str

Returns:

a Python list

to_dict(protocol='jsonschema', **kwargs)#

Convert the object into a Python list.

Parameters:

protocol (str) – jsonschema or protobuf

Return type:

List

Returns:

a Python list

classmethod from_dict(values, protocol='jsonschema', **kwargs)#
Return type:

T