def from_json_string(json_string, convert=True): """ Load a pandapower network from a JSON string. The index of the returned network is not necessarily in the same order as the original network. Index columns of all pandas DataFrames are sorted in ascending order. INPUT: **json_string** (string) - The json string representation of the network OUTPUT: **convert** (bool) - use the convert format function to **net** (dict) - The pandapower format network EXAMPLE: >>> net = pp.from_json_string(json_str) """ data = json.loads(json_string, cls=PPJSONDecoder) try: pd_dicts = dicts_to_pandas(data) net = from_dict_of_dfs(pd_dicts) if convert: convert_format(net) return net except UserWarning: # Can be deleted in the future, maybe now return from_json_dict(data, convert=convert)
def from_json(filename, convert=True): """ Load a pandapower network from a JSON file. The index of the returned network is not necessarily in the same order as the original network. Index columns of all pandas DataFrames are sorted in ascending order. INPUT: **filename** (string or file) - The absolute or relative path to the input file or file-like object OUTPUT: **convert** (bool) - use the convert format function to **net** (dict) - The pandapower format network EXAMPLE: >>> net = pp.from_json("example.json") """ if hasattr(filename, 'read'): data = json.load(filename, cls=PPJSONDecoder) elif not os.path.isfile(filename): raise UserWarning("File %s does not exist!!" % filename) else: with open(filename) as data_file: data = json.load(data_file, cls=PPJSONDecoder) try: pd_dicts = dicts_to_pandas(data) net = from_dict_of_dfs(pd_dicts) if convert: convert_format(net) return net except UserWarning: # Can be deleted in the future, maybe now return from_json_dict(data, convert=convert)