Skip to content
Myr

Support lowercase name in from_entries (fix #990)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 32e5e6a · Browse files · 3 files+4 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+4 added−8 removed

  • tests:+2 added−6 removed
  • other:+2 added−2 removed

3 files+4 added−8 removed

modified:docs/content/3.manual/manual.yml+1 added-1 removed
822 unmodified lines
823 `from_entries` does the opposite conversion, and824 `with_entries(foo)` is a shorthand for `to_entries |825 map(foo) | from_entries`, useful for doing some operation to826 all keys and values of an object. `from_entries` accepts key, Key,827 Name, value and Value as keys.827 name, Name, value and Value as keys.828829 examples:830 - program: 'to_entries'831 input: '{"a": 1, "b": 2}'
2116 unmodified lines
modified:src/builtin.c+1 added-1 removed
1391 unmodified lines
1392 "def recurse: recurse(.[]?);",1393 "def recurse_down: recurse;",13941395 "def to_entries: [keys_unsorted[] as $k | {key: $k, value: .[$k]}];",1396 "def from_entries: map({(.key // .Key // .Name): (if has(\"value\") then .value else .Value end)}) | add | .//={};",1396 "def from_entries: map({(.key // .Key // .name // .Name): (if has(\"value\") then .value else .Value end)}) | add | .//={};",1397 "def with_entries(f): to_entries | map(f) | from_entries;",1398 "def reverse: [.[length - 1 - range(0;length)]];",1399 "def indices($i): if type == \"array\" and ($i|type) == \"array\" then .[$i]"1400 " elif type == \"array\" then .[[$i]]"
308 unmodified lines
modified:tests/jq.test+2 added-6 removed
1070 unmodified lines
1071{"a": 1, "b": 2}1072[{"key":"a", "value":1}, {"key":"b", "value":2}]10731074from_entries1075[{"key":"a", "value":1}, {"Key":"b", "value":2}]1076{"a": 1, "b": 2}1075[{"key":"a", "value":1}, {"Key":"b", "Value":2}, {"name":"c", "value":3}, {"Name":"d", "Value":4}]1076{"a": 1, "b": 2, "c": 3, "d": 4}10771078from_entries1079[{"key":"a", "Value":1}, {"Name":"b", "value":2}]1080{"a": 1, "b": 2}10811078with_entries(.key |= "KEY_" + .)1079{"a": 1, "b": 2}1080{"KEY_a": 1, "KEY_b": 2}1081
207 unmodified lines