Pointers and references: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: disambiguation)
(→‎{{header|jq}}: special case)
Line 1,043: Line 1,043:
# getjsonpointer() is like getpath() but for jsonpointer pointers
# getjsonpointer() is like getpath() but for jsonpointer pointers
def getjsonpointer($pointer):
def getjsonpointer($pointer):
if $pointer == "" then . # special case
. as $in
else
# first decode ~1, then ~0
# first decode ~1, then ~0
| ($pointer | split("/") | .[1:]
($pointer | split("/") | .[1:]
| map(gsub("~1"; "/") | gsub("~0"; "~"))) as $array
| map(gsub("~1"; "/") | gsub("~0"; "~"))) as $array
| disambiguatePath($array) as $apath
| disambiguatePath($array) as $apath
| if $apath then getpath($apath) else null end;
| if $apath then getpath($apath) else null end
end;


# like getpath() but allow $p to be a jsonpointer or an array
# like getpath() but allow $p to be a jsonpointer or an array