ujson – JSON encoding and decoding

Convert between Python objects and the JSON data format.

dump(object, stream, separators=(', ', ': '))

Serializes an object to a JSON string and write it to a stream.

Parameters:
  • obj – Object to serialize.

  • stream – Stream to write the output to.

  • separators (tuple) – An (item_separator, key_separator) tuple to specify how elements should be separated.

dumps(object, separators=(', ', ': '))

Serializes an object to JSON and return it as a string

Parameters:
  • obj – Object to serialize.

  • separators (tuple) – An (item_separator, key_separator) tuple to specify how elements should be separated.

Returns:

The JSON string.

load(stream)

Parses the stream to interpret and deserialize the JSON data to a MicroPython object.

Parsing continues until end-of-file is encountered. A ValueError is raised if the data in stream is not correctly formed.

Parameters:

stream – Stream from which to read the JSON string.

Returns:

The deserialized MicroPython object.

loads(string)

Parses the string to interpret and deserialize the JSON data to a MicroPython object.

A ValueError is raised if the string is not correctly formed.

Parameters:

string (str) – JSON string to decode.

Returns:

The deserialized MicroPython object.