json¶
Classes
|
Functions
|
Write given data in json format in file with given name. |
|
Write given data in json format in file with given name asynchronously. |
|
Normalize semi-structured JSON data into a flat table. |
|
Decoding data from json file with given filename. |
|
Add prefix and suffix to keys of given dict. |
|
Validate json data. |
Description
-
dump_json_file(data, filename, indent=
4
)[source]¶ Write given data in json format in file with given name.
- Parameters
- Returns
None
- Return type
NoneType
- Usage example
from supervisely.io.json import dump_json_file data = {1: 'example'} dump_json_file(data, '/home/admin/work/projects/examples/1.json')
-
async dump_json_file_async(data, filename, indent=
4
)[source]¶ Write given data in json format in file with given name asynchronously.
- Parameters
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly data = {1: 'example'} loop = sly.utils.get_or_create_event_loop() coro = sly.json.dump_json_file_async(data, '/home/admin/work/projects/examples/1.json') if loop.is_running(): future = asyncio.run_coroutine_threadsafe(coro, loop) future.result() else: loop.run_until_complete(coro)
- load_json_file(filename)[source]¶
Decoding data from json file with given filename.
- Parameters
- filename : str
Target file path.
- Raises
IsADirectoryError – If given filename is a directory, not a file.
FileNotFoundError – If file with given filename was not found.
RuntimeError – If can not decode json file.
- Returns
Json format as a dict
- Return type
- Usage example
from supervisely.io.json import load_json_file json_example = load_json_file('/home/admin/work/projects/examples/ann.json') print(json_example) # Output: { # "description": "", # "tags": [], # "size": { # "height": 800, # "width": 1067 # }, # "objects": [ # { # "id": 619053179, # "classId": 2791451, # "description": "", # "geometryType": "bitmap", # "labelerLogin": "alexxx", # "createdAt": "2021-02-10T08:36:33.898Z", # "updatedAt": "2021-02-10T08:39:24.828Z", # "tags": [], # "classTitle": "lemon", # "bitmap": { # "data": "eJwBZgOZ/IlQTkcNChoKAAAADUlIR...AiRp9+EwAAAABJRU5ErkJgggn2cM0=", # "origin": [ # 531, # 120 # ] # } # }, # { # "id": 619053347, # "classId": 2791453, # "description": "", # "geometryType": "rectangle", # "labelerLogin": "alexxx", # "createdAt": "2021-02-10T08:39:08.369Z", # "updatedAt": "2021-02-10T08:39:24.828Z", # "tags": [], # "classTitle": "kiwi", # "points": { # "exterior": [ # [ # 764, # 387 # ], # [ # 967, # 608 # ] # ], # "interior": [] # } # }, # { # "id": 619053355, # "classId": 2791453, # "description": "", # "geometryType": "rectangle", # "labelerLogin": "alexxx", # "createdAt": "2021-02-10T08:39:16.938Z", # "updatedAt": "2021-02-10T08:39:24.828Z", # "tags": [], # "classTitle": "kiwi", # "points": { # "exterior": [ # [ # 477, # 543 # ], # [ # 647, # 713 # ] # ], # "interior": [] # } # } # ] # }
-
modify_keys(data, prefix=
None
, suffix=None
)[source]¶ Add prefix and suffix to keys of given dict.
- Parameters
- Returns
New dict with prefix and suffix in keys
- Return type
- Usage example
from supervisely.io.json import modify_keys data = {'1': 'example', '3': 4} new_data = modify_keys(data, prefix='pr_', suffix='_su') print(new_data) # Output: {'pr_1_su': 'example', 'pr_3_su': 4}