Checks whether json_type is a dict or a string. If it is already a dict, it is returned as-is. If it is not, it is converted to a dict by means of json.loads(json_type) :meta private: :param json_type: input json or parsed dict :param dict_copy: if dict is
(json_type, dict_copy = True)
| 90 | |
| 91 | @staticmethod |
| 92 | def check_json(json_type, dict_copy = True): |
| 93 | """ |
| 94 | Checks whether json_type is a dict or a string. If it is already a dict, it is returned as-is. |
| 95 | If it is not, it is converted to a dict by means of json.loads(json_type) |
| 96 | |
| 97 | :meta private: |
| 98 | |
| 99 | :param json_type: input json or parsed dict |
| 100 | :param dict_copy: if dict is passed and it is changed outside - should be True! |
| 101 | :return: Dictionary parsed from json or original dict |
| 102 | """ |
| 103 | if service_utils.is_dict(json_type): |
| 104 | return json_type.copy() if dict_copy else json_type |
| 105 | elif service_utils.is_string(json_type): |
| 106 | return json.loads(json_type) |
| 107 | else: |
| 108 | raise ValueError("json_type should be a json dict or string.") |
| 109 | |
| 110 | def __str__(self): |
| 111 | d = { |
no outgoing calls
no test coverage detected