Load user-supplied value as a JSON dict. :param user_value: User-supplied value to load as a JSON dict
(user_value: str)
| 139 | |
| 140 | |
| 141 | def process_json(user_value: str): |
| 142 | """Load user-supplied value as a JSON dict. |
| 143 | |
| 144 | :param user_value: User-supplied value to load as a JSON dict |
| 145 | """ |
| 146 | try: |
| 147 | user_dict = json.loads(user_value, object_pairs_hook=OrderedDict) |
| 148 | except Exception as error: |
| 149 | # Leave it up to click to ask the user again |
| 150 | msg = 'Unable to decode to JSON.' |
| 151 | raise InvalidResponse(msg) from error |
| 152 | |
| 153 | if not isinstance(user_dict, dict): |
| 154 | # Leave it up to click to ask the user again |
| 155 | msg = 'Requires JSON dict.' |
| 156 | raise InvalidResponse(msg) |
| 157 | |
| 158 | return user_dict |
| 159 | |
| 160 | |
| 161 | class JsonPrompt(PromptBase[dict]): |
no outgoing calls
searching dependent graphs…