getpath/1 should be a path expression (fix #1358)

It needs to be possible to do something like

    getpath($paths[]) += 1

meaning: increment all the paths in . that are listed in $paths[].

In order to do this getpath() needs to update the jq->path and
jq->value_at_path as necessary.
This commit is contained in:
Nicolas Williams committed 2017-02-28 21:54:30 -06:00
1 parent 63791b795a
commit 2fcb257168
3 files changed
+38 -1

No files matched your search

+12
View File
@@ -842,6 +842,18 @@ def inc(x): x |= .+1; inc(.[].a)
[{"a":1,"b":2},{"a":2,"b":4},{"a":7,"b":8}]
[{"a":2,"b":2},{"a":3,"b":4},{"a":8,"b":8}]
# #1358, getpath/1 should work in path expressions
.[] | try (getpath(["a",0,"b"]) |= 5) catch .
[null,{"b":0},{"a":0},{"a":null},{"a":[0,1]},{"a":{"b":1}},{"a":[{}]},{"a":[{"c":3}]}]
{"a":[{"b":5}]}
{"b":0,"a":[{"b":5}]}
"Cannot index number with number"
{"a":[{"b":5}]}
"Cannot index number with string \"b\""
"Cannot index object with number"
{"a":[{"b":5}]}
{"a":[{"c":3,"b":5}]}
.[2][3] = 1
[4]
[4, null, [null, null, null, 1]]