Accepts a JSON formatted data structure
| 363 | |
| 364 | |
| 365 | class JSON(Type): |
| 366 | """Accepts a JSON formatted data structure""" |
| 367 | |
| 368 | __slots__ = () |
| 369 | |
| 370 | def __call__(self, value): |
| 371 | if type(value) in (str, bytes): |
| 372 | try: |
| 373 | return json_converter.loads(value) |
| 374 | except Exception: |
| 375 | raise ValueError("Incorrectly formatted JSON provided") |
| 376 | if type(value) is list: |
| 377 | # If Falcon is set to comma-separate entries, this segment joins them again. |
| 378 | try: |
| 379 | fixed_value = ",".join(value) |
| 380 | return json_converter.loads(fixed_value) |
| 381 | except Exception: |
| 382 | raise ValueError("Incorrectly formatted JSON provided") |
| 383 | else: |
| 384 | return value |
| 385 | |
| 386 | |
| 387 | class Multi(Type): |