Replies: 3 comments
-
The hash prefix is there to point to an object (aka dict/map) key instead of the value associated with the key, or an array (aka list/sequence) index instead of the value at that index. The Relative JSON Pointer draft spec supports this kind of operation. By adding this
Here we're asserting that if data = {"foo": {"bar": [1, 2, 3], "#baz": "hello"}}
assert JSONPointer("/foo/bar/#1").resolve(data) == 1 And here we're checking that pointing to an out of bounds index raises an exception. This is the same behavior with or without a hash. with pytest.raises(JSONPointerIndexError):
JSONPointer("/foo/bar/#9").resolve(data) Note that we have a similar situation with the non-standard There's plenty of room for improvement in |
Beta Was this translation helpful? Give feedback.
-
So to summarize: Arrays: Objects: Is this accurate? Also, this: assert JSONPointer("/foo/bar/01").resolve(data) == 1 Is intended to fail with a But the following currently succeeds. Perhaps this is a bug? assert JSONPointer("/foo/bar/#01").resolve(data) == 1 |
Beta Was this translation helpful? Give feedback.
-
Yep, that's accurate. Unless an object has a key that actually starts with a hash. In which case we resolve the key to its associated value. data = {"foo": {"bar": [1, 2, 3], "#baz": "hello"}}
assert JSONPointer("/foo/#baz").resolve(data) == "hello" # True
Yes, I'd call that a bug. We should follow the "digits without a leading '0'" policy from RFC 6901. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Can you explain what the hash prefix does and how you intend it to work? I've got all but 3 tests in test_json_pointer.py passing. But I'm not exactly sure how the hash symbol is supposed to work. Can you explain this test case?
Beta Was this translation helpful? Give feedback.
All reactions