Class DocJsonFile
- class ooodev.io.json.DocJsonFile(doc, root_dir='json')[source]
Class that read and write JSON files to and from the document.
- Parameters:
doc (OfficeDocumentT) –
root_dir (str) –
- __init__(doc, root_dir='json')[source]
- Parameters:
doc (OfficeDocumentT) –
root_dir (str) –
- file_exist(file_name)[source]
Checks if a file exists in the document.
- Parameters:
file_name (str) – The name of the file.
- Returns:
True if the file exists, False otherwise.
- Return type:
bool
- read_json(file_name)[source]
Reads a JSON file from the document.
- Parameters:
file_name (str) – The name of the JSON file.
- Raises:
FileNotFoundError – If the file does not exist.
JsonError – If there is an error reading the file.
JsonLoadError – If there is an error parsing the file.
- Returns:
The JSON data or None if the file does not exist or there is an error reading the file.
- Return type:
dict
- write_json(file_name, data, mode='w')[source]
Writes a JSON file to the document.
- Parameters:
file_name (str) – The name of the JSON file. The file name will have
.json
appended to it if it does not already have it.data (Any) – The data to write to the file.
mode – (str, optional): The mode to open the file. Defaults to “w”. mode
w
will overwrite the file. modea
will append to the file. modex
will create a new file and write to it failing if the file already exists
- Raises:
JsonError – If there is an error writing the file.
JsonDumpError – If there is an error serializing the data.
- Return type:
None
- Returns:
None