From c8dc164566bde82282b3192b677ca25997bafa0c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 17 Oct 2015 20:50:40 -0700 Subject: [PATCH] Support lowercase name in from_entries (fix #990) --- docs/content/3.manual/manual.yml | 2 +- src/builtin.c | 2 +- tests/jq.test | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index 39abfd0..d9dd3b1 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -824,7 +824,7 @@ sections: `with_entries(foo)` is a shorthand for `to_entries | map(foo) | from_entries`, useful for doing some operation to 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: - program: 'to_entries' diff --git a/src/builtin.c b/src/builtin.c index 3b92097..fccb602 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1393,7 +1393,7 @@ static const char* const jq_builtins[] = { "def recurse_down: recurse;", "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 reverse: [.[length - 1 - range(0;length)]];", "def indices($i): if type == \"array\" and ($i|type) == \"array\" then .[$i]" diff --git a/tests/jq.test b/tests/jq.test index c7c1d37..879de16 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1072,12 +1072,8 @@ to_entries [{"key":"a", "value":1}, {"key":"b", "value":2}] from_entries -[{"key":"a", "value":1}, {"Key":"b", "value":2}] -{"a": 1, "b": 2} - -from_entries -[{"key":"a", "Value":1}, {"Name":"b", "value":2}] -{"a": 1, "b": 2} +[{"key":"a", "value":1}, {"Key":"b", "Value":2}, {"name":"c", "value":3}, {"Name":"d", "Value":4}] +{"a": 1, "b": 2, "c": 3, "d": 4} with_entries(.key |= "KEY_" + .) {"a": 1, "b": 2} -- 2.40.0