agentscope.service.file.json module
Operators for json file and directory.
- agentscope.service.file.json.read_json_file(file_path: str) ServiceResponse [source]
Read and parse a JSON file.
- Parameters:
file_path (str) – The path to the JSON file to be read.
- Returns:
Where the boolean indicates success, the Any is the parsed JSON content (typically a dict), and the str contains an error message if any, including the error type.
- Return type:
ServiceResponse
- agentscope.service.file.json.write_json_file(file_path: str, data: Any, overwrite: bool = False) ServiceResponse [source]
Serialize data to a JSON file.
- Parameters:
file_path (str) – The path to the file where the JSON data will be written.
data (Any) – The data to serialize to JSON.
overwrite (bool) – Whether to overwrite the file if it already exists.
- Returns:
where the boolean indicates success, and the str contains an error message if any, including the error type.
- Return type:
ServiceResponse