watex.utils.funcutils.parse_json#
- watex.utils.funcutils.parse_json(json_fn=None, data=None, todo='load', savepath=None, verbose=0, **jsonkws)[source]#
Parse Java Script Object Notation file and collect data from JSON config file.
- Parameters
json_fn – Json filename, URL or output JSON name if data is given and todo is set to
dump.Otherwise the JSON output filename should be the data or the given variable name.data – Data in Python obj to serialize.
todo – Action to perform with JSON: - load: Load data from the JSON file - dump: serialize data from the Python object and create a JSON file
savepath – If
defaultshould save the json_fn If path does not exist, should save to the <’_savejson_’> default path .verbose – int, control the verbosity. Output messages
- Example
>>> PATH = 'data/model' >>> k_ =['model', 'iter', 'mesh', 'data'] >>> try : INVERS_KWS = { s +'_fn':os.path.join(PATH, file) for file in os.listdir(PATH) for s in k_ if file.lower().find(s)>=0 } except : INVERS=dict() >>> TRES=[10, 66, 70, 100, 1000, 3000]# 7000] >>> LNS =['river water','fracture zone', 'MWG', 'LWG', 'granite', 'igneous rocks', 'basement rocks'] >>> import watex.utils.funcutils as FU >>> geo_kws ={'oc2d': INVERS_KWS, 'TRES':TRES, 'LN':LNS} # serialize json data and save to 'jsontest.json' file >>> FU.parse_json(json_fn = 'jsontest.json', data=geo_kws, todo='dump', indent=3, savepath ='data/saveJSON', sort_keys=True) # Load data from 'jsontest.json' file. >>> FU.parse_json(json_fn='data/saveJSON/jsontest.json', todo ='load')