json_extends#
- class pams.utils.json_extends(whole_json, parent_name, target_json, excludes_fields=None)[source]#
- extend target json. If “extends” keys are included in target_json, this try to extend the json dict recursively.
For the extension, the value for “extends” field is found in whole_json and target_json is extended using the dict under the found part of whole_json. This process is recursively repeated. “parent_name” is only used for avoiding circle extension of target_json and it should be parent key of taregt_json.
- Parameters:
whole_json (Dict) – whole of json.
parent_name (str) – parent name of target_json.
target_json (Dict) – target json.
excludes_fields (List[str], Optional) – exclude list from json field.
- Returns:
json output.
- Return type:
Dict
Examples
>>> from pams.utils.json_extends import json_extends >>> whole_json = {"parent": {"parent_attr": "1", "override_attr": "1"}} >>> target_json = {"extends": "parent", "child_attr": "0", "override_attr": "0"} >>> json_extends(whole_json=whole_json, parent_name="child", target_json=target_json) {'parent_attr': '1', 'override_attr': '0', 'child_attr': '0'}