msl.io.writers.json_ module
Writer for a JSON file format. The corresponding Reader is
JSONReader.
- class msl.io.writers.json_.JSONWriter(file=None, **metadata)[source]
Bases:
WriterCreate a JSON writer.
You can use
JSONWriteras a context manager. For example,>>> with JSONWriter('example.json') as root: ... dset = root.create_dataset('dset', data=[1, 2, 3]) ... root.update_context_kwargs(indent=4)
This will automatically write root to the specified file using
indent=4as a keyword argument to thewrite()method when the with block exits.- Parameters:
- write(file=None, root=None, **kwargs)[source]
Write to a JSON file.
The first line in the output file contains a description that the file was created by the
JSONWriter. It begins with a#and contains a version number.Version 1.0 specifications
- Parameters:
file (path-like or file-like, optional) – The file to write the root to. If
Nonethen uses the value of file that was specified whenJSONWriterwas instantiated.root (
Root, optional) – Write root in JSON format. IfNonethen write theGroups andDatasets in thisJSONWriter.**kwargs – Accepts mode, encoding and errors keyword arguments which are passed to
open(). The default encoding value is'utf-8'and the default errors value is'strict'. All additional keyword arguments are passed to json.dump. The default indentation is 2.