| 43 | value = json.loads(raw.decode("utf-8"), object_pairs_hook=unique_object, parse_int=integer, |
| 44 | parse_float=refuse_number, parse_constant=refuse_number) |
| 45 | def validate(item, depth=0): |
| 46 | if isinstance(item, (dict, list)): |
| 47 | if depth >= 128: |
| 48 | raise ValueError("JSON exceeds nesting limit") |
| 49 | if isinstance(item, dict): |
| 50 | for key, child in item.items(): |
| 51 | key.encode("utf-8", errors="strict") |
| 52 | validate(child, depth + 1) |
| 53 | else: |
| 54 | for child in item: |
| 55 | validate(child, depth + 1) |
| 56 | elif isinstance(item, str): |
| 57 | item.encode("utf-8", errors="strict") |
| 58 | validate(value) |
| 59 | return value |
| 60 | |