Support lowercase name in from_entries (fix #990)
This commit is contained in:
1 parent
32e5e6af4b
commit
c8dc164566
3 files changed
+4
-8
No files matched your search
@@ -824,7 +824,7 @@ sections:
|
|||||||
`with_entries(foo)` is a shorthand for `to_entries |
|
`with_entries(foo)` is a shorthand for `to_entries |
|
||||||
map(foo) | from_entries`, useful for doing some operation to
|
map(foo) | from_entries`, useful for doing some operation to
|
||||||
all keys and values of an object. `from_entries` accepts key, Key,
|
all keys and values of an object. `from_entries` accepts key, Key,
|
||||||
Name, value and Value as keys.
|
name, Name, value and Value as keys.
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
- program: 'to_entries'
|
- program: 'to_entries'
|
||||||
|
|||||||
+1
-1
@@ -1393,7 +1393,7 @@ static const char* const jq_builtins[] = {
|
|||||||
"def recurse_down: recurse;",
|
"def recurse_down: recurse;",
|
||||||
|
|
||||||
"def to_entries: [keys_unsorted[] as $k | {key: $k, value: .[$k]}];",
|
"def to_entries: [keys_unsorted[] as $k | {key: $k, value: .[$k]}];",
|
||||||
"def from_entries: map({(.key // .Key // .Name): (if has(\"value\") then .value else .Value end)}) | add | .//={};",
|
"def from_entries: map({(.key // .Key // .name // .Name): (if has(\"value\") then .value else .Value end)}) | add | .//={};",
|
||||||
"def with_entries(f): to_entries | map(f) | from_entries;",
|
"def with_entries(f): to_entries | map(f) | from_entries;",
|
||||||
"def reverse: [.[length - 1 - range(0;length)]];",
|
"def reverse: [.[length - 1 - range(0;length)]];",
|
||||||
"def indices($i): if type == \"array\" and ($i|type) == \"array\" then .[$i]"
|
"def indices($i): if type == \"array\" and ($i|type) == \"array\" then .[$i]"
|
||||||
|
|||||||
+2
-6
@@ -1072,12 +1072,8 @@ to_entries
|
|||||||
[{"key":"a", "value":1}, {"key":"b", "value":2}]
|
[{"key":"a", "value":1}, {"key":"b", "value":2}]
|
||||||
|
|
||||||
from_entries
|
from_entries
|
||||||
[{"key":"a", "value":1}, {"Key":"b", "value":2}]
|
[{"key":"a", "value":1}, {"Key":"b", "Value":2}, {"name":"c", "value":3}, {"Name":"d", "Value":4}]
|
||||||
{"a": 1, "b": 2}
|
{"a": 1, "b": 2, "c": 3, "d": 4}
|
||||||
|
|
||||||
from_entries
|
|
||||||
[{"key":"a", "Value":1}, {"Name":"b", "value":2}]
|
|
||||||
{"a": 1, "b": 2}
|
|
||||||
|
|
||||||
with_entries(.key |= "KEY_" + .)
|
with_entries(.key |= "KEY_" + .)
|
||||||
{"a": 1, "b": 2}
|
{"a": 1, "b": 2}
|
||||||
|
|||||||
Reference in new issue
Block a user