Add indices(s), improve index(s), rindex(s)
Now these deal with arrays as input and `s` being an array or a scalar.
This commit is contained in:
1 parent
ef4f3a54fe
commit
1dbe9317bc
6 files changed
+61
-4
No files matched your search
@@ -688,8 +688,9 @@ static const char* const jq_builtins[] = {
|
||||
"def from_entries: map({(.key): .value}) | add;",
|
||||
"def with_entries(f): to_entries | map(f) | from_entries;",
|
||||
"def reverse: [.[length - 1 - range(0;length)]];",
|
||||
"def index(i): .[i][0];",
|
||||
"def rindex(i): .[i][-1:][0];",
|
||||
"def indices(i): if type == \"array\" and (i|type) == \"array\" then .[i] elif type == \"array\" then .[[i]] else .[i] end;",
|
||||
"def index(i): if type == \"array\" and (i|type) == \"array\" then .[i] elif type == \"array\" then .[[i]] else .[i] end | .[0];",
|
||||
"def rindex(i): if type == \"array\" and (i|type) == \"array\" then .[i] elif type == \"array\" then .[[i]] else .[i] end | .[-1:][0];",
|
||||
"def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 0);",
|
||||
"def leaf_paths: . as $dot|paths|select(. as $p|$dot|getpath($p)|type|. != \"array\" and . != \"object\");",
|
||||
"def any: reduce .[] as $i (false; . or $i);",
|
||||
|
||||
Reference in new issue
Block a user