I have a question.
Let’s assume I had a json doc like this:
{
"counts": [
17,
1014,
22,
9,
11
],
"values": [
"5",
"10",
"15",
"20",
"25"
]
}
and I wanted to get a result like this:
{
"5":17,
"10":1014,
"15":22,
"20":9,
"25":11
}
basically the array elements assigned as key value pairs one after the other. How can I achieve that?
I tried jq with_entries(.values = .counts)
and with_entries(.values[] = .counts[])
but it didn’t work.
2
Answers
I’d use
transpose
withreduce
:Output:
Online Demo
Here are two
transpose
-free solutions:Demo
Demo
Output: