Key folding demo.
()
| 99 | print(toon_pipe) |
| 100 | |
| 101 | def demo_key_folding(): |
| 102 | """Key folding demo.""" |
| 103 | print_section("Key Folding for Deeply Nested Data") |
| 104 | |
| 105 | data = { |
| 106 | "api": { |
| 107 | "response": { |
| 108 | "data": { |
| 109 | "user": { |
| 110 | "name": "Alice" |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | print("Without key folding:") |
| 118 | toon_normal = encode(data) |
| 119 | print(toon_normal) |
| 120 | |
| 121 | print("\nWith key folding:") |
| 122 | toon_folded = encode(data, {"key_folding": "safe"}) |
| 123 | print(toon_folded) |
| 124 | |
| 125 | print("\nWith path expansion on decode:") |
| 126 | result = decode(toon_folded, {"expand_paths": "safe"}) |
| 127 | print(json.dumps(result, indent=2)) |
| 128 | |
| 129 | def main(): |
| 130 | """Run all demos.""" |
no test coverage detected
searching dependent graphs…