RFC6901 JSON Pointer implementation in OCaml using jsont
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 140 lines 4.0 kB view raw
1JSON Pointer Evaluation Tests (RFC 6901 Section 5) 2 3Using the RFC 6901 example document: 4 $ cat data/rfc6901_example.json 5 { 6 "foo": ["bar", "baz"], 7 "": 0, 8 "a/b": 1, 9 "c%d": 2, 10 "e^f": 3, 11 "g|h": 4, 12 "i\\j": 5, 13 "k\"l": 6, 14 " ": 7, 15 "m~n": 8 16 } 17 18Root pointer returns whole document: 19 $ ./test_pointer.exe eval data/rfc6901_example.json "" 20 OK: {"foo":["bar","baz"],"":0,"a/b":1,"c%d":2,"e^f":3,"g|h":4,"i\\j":5,"k\"l":6," ":7,"m~n":8} 21 22RFC 6901 examples: 23 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo" 24 OK: ["bar","baz"] 25 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/0" 26 OK: "bar" 27 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/1" 28 OK: "baz" 29 $ ./test_pointer.exe eval data/rfc6901_example.json "/" 30 OK: 0 31 $ ./test_pointer.exe eval data/rfc6901_example.json "/a~1b" 32 OK: 1 33 $ ./test_pointer.exe eval data/rfc6901_example.json "/c%d" 34 OK: 2 35 $ ./test_pointer.exe eval data/rfc6901_example.json "/e^f" 36 OK: 3 37 $ ./test_pointer.exe eval data/rfc6901_example.json "/g|h" 38 OK: 4 39 $ ./test_pointer.exe eval data/rfc6901_example.json '/i\j' 40 OK: 5 41 $ ./test_pointer.exe eval data/rfc6901_example.json '/k"l' 42 OK: 6 43 $ ./test_pointer.exe eval data/rfc6901_example.json "/ " 44 OK: 7 45 $ ./test_pointer.exe eval data/rfc6901_example.json "/m~0n" 46 OK: 8 47 48Error: nonexistent member: 49 $ ./test_pointer.exe eval data/rfc6901_example.json "/nonexistent" 50 ERROR: JSON Pointer: member 'nonexistent' not found 51 File "-": 52 53Error: index out of bounds: 54 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/2" 55 ERROR: JSON Pointer: index 2 out of bounds (array has 2 elements) 56 File "-": 57 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/99" 58 ERROR: JSON Pointer: index 99 out of bounds (array has 2 elements) 59 File "-": 60 61Error: invalid array index (not a valid integer): 62 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/bar" 63 ERROR: JSON Pointer: invalid array index 'bar' 64 File "-": 65 66Error: end marker not allowed in get: 67 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/-" 68 ERROR: Invalid JSON Pointer: '-' not allowed in navigation pointer 69 70Error: navigating through primitive (string): 71 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/0/0" 72 ERROR: JSON Pointer: cannot index into string with '0' 73 File "-": 74 $ ./test_pointer.exe eval data/rfc6901_example.json "/foo/0/bar" 75 ERROR: JSON Pointer: cannot index into string with 'bar' 76 File "-": 77 78Nested evaluation with deep nesting: 79 $ cat data/nested.json 80 { 81 "a": { 82 "b": { 83 "c": { 84 "d": "deep value" 85 } 86 } 87 }, 88 "arr": [[1, 2], [3, 4]], 89 "mixed": { "list": [{"x": 1}, {"y": 2}] } 90 } 91 $ ./test_pointer.exe eval data/nested.json "/a/b/c/d" 92 OK: "deep value" 93 $ ./test_pointer.exe eval data/nested.json "/arr/0/1" 94 OK: 2 95 $ ./test_pointer.exe eval data/nested.json "/arr/1/0" 96 OK: 3 97 $ ./test_pointer.exe eval data/nested.json "/mixed/list/0/x" 98 OK: 1 99 $ ./test_pointer.exe eval data/nested.json "/mixed/list/1/y" 100 OK: 2 101 102Null value handling: 103 $ cat data/nulls.json 104 { 105 "null": null, 106 "nested": { "null": null } 107 } 108 $ ./test_pointer.exe eval data/nulls.json "/null" 109 OK: null 110 $ ./test_pointer.exe eval data/nulls.json "/nested/null" 111 OK: null 112 113Boolean values: 114 $ cat data/booleans.json 115 { 116 "true": true, 117 "false": false 118 } 119 $ ./test_pointer.exe eval data/booleans.json "/true" 120 OK: true 121 $ ./test_pointer.exe eval data/booleans.json "/false" 122 OK: false 123 124Empty key access: 125 $ ./test_pointer.exe eval data/rfc6901_example.json "/" 126 OK: 0 127 128Unicode member access: 129 $ cat data/unicode.json 130 { 131 "café": "coffee", 132 "日本語": "japanese", 133 "🎉": "party" 134 } 135 $ ./test_pointer.exe eval data/unicode.json "/café" 136 OK: "coffee" 137 $ ./test_pointer.exe eval data/unicode.json "/日本語" 138 OK: "japanese" 139 $ ./test_pointer.exe eval data/unicode.json "/🎉" 140 OK: "party"