Skip to content

Instantly share code, notes, and snippets.

@geraintluff
Last active March 25, 2023 07:14
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geraintluff/5911303 to your computer and use it in GitHub Desktop.
Save geraintluff/5911303 to your computer and use it in GitHub Desktop.
Additional Relative JSON Pointer examples
{
"test": ["foo", "bar"],
"child": {
"grandchild": 12345
},
"sibling": "sibling value",
"awkwardly/named~variable": true
}
Starting value Relative JSON Pointer result
-------------------------------------------------------------------------
"bar" "0" "bar"
"bar" "0#" 1
"bar" "1" ["foo", "bar"]
"bar" "1/0" "foo"
"bar" "1/1" "bar"
"bar" "1#" "test"
"bar" "2" << the whole document >>
"bar" "2#" << fails >>
"bar" "3" << fails >>
12345 "0" 12345
12345 "0#" "grandchild"
12345 "1" {"grandchild": 12345}
12345 "1/grandchild" 12345
12345 "1#" "child"
12345 "2" << the whole document >>
12345 "2/sibling" "sibling value"
12345 "2/test/1" "bar"
{"grandchild": 12345} "0" {"grandchild": 12345}
{"grandchild": 12345} "0#" "child"
{"grandchild": 12345} "0/grandchild" 12345
{"grandchild": 12345} "1/sibling" "sibling value"
{"grandchild": 12345} "2" << the whole document >>
"sibling value" "0" "sibling value"
"sibling value" "0#" "sibling"
"sibling value" "1" << the whole document >>
"sibling value" "1/awkwardly~1named~0variable" true
true "0" true
true "0#" "awkwardly/named-variable"
@ArnoCan
Copy link

ArnoCan commented Apr 26, 2018

Hello,
I am currently testing a new library with relative pointers support. The example

{"grandchild": 12345} "2" << the whole document >>

seems to be erroneous, it is also inconsistent with the example

{"grandchild": 12345} "1/sibling" "sibling value

because this implies "1" as the root of the whole document.
The valid entry should be

{"grandchild": 12345} "1" << the whole document >>

WKR
Arno-Can Uestuensoez

@iGarym
Copy link

iGarym commented Dec 26, 2018

@ArnoCan
Agree with u.
{"grandchild": 12345} "1" should be "<<the whole document >>"
{"grandchild": 12345} "2" should be "<<fails>>"

@michael-o
Copy link

There is a typo in line 30, resul should read "awkwardly/named~variable".

@yww325
Copy link

yww325 commented Jul 23, 2020

how to use the Relative JSON Pointer in a schema actually? Do I need to use $data or $ref?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment