easyidp.jsonfile.dict2json#

easyidp.jsonfile.dict2json(data_dict, json_path, indent=None, encoding='utf-8')#

Save dict object to the same structure json file

Parameters:
  • data_dict (dict) – the dict object want to save as json file

  • json_path (str) – the path including json file name to save the json file e.g. D:/xxx/xxxx/save.json

  • indent (int | None) – whether save “readable” json with indent, default 0 without indent

  • encoding (str) – the encoding type of output file

Example

>>> import easyidp as idp
>>> a = {"test": {"rua": np.asarray([[12, 34], [45, 56]])}, "hua":[np.int32(34), np.float64(34.567)]}
>>> idp.jsonfile.dict2json(a, "/path/to/save/json_file.json")

Note

Dict without indient:

>>> print(json.dumps(data), indent=0)
{"age": 4, "name": "niuniuche", "attribute": "toy"}

Dict with 4 space as indient:

>>> print(json.dumps(data,indent=4))
{
    "age": 4,
    "name": "niuniuche",
    "attribute": "toy"
}