Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    This is helpful. Is there a way I can run transpose and map so that I end up with a single object instead of an array of objects? or perhaps another transformation that can merge this resulting array into a single object? Commented Dec 8, 2016 at 18:56
  • 2
    Ah, I added | add to the end and got what I wanted. Commented Dec 8, 2016 at 18:57
  • Here's an example that references a path to get to the initial array. jq ".results[0].result.tag | [.classes, .probs] | transpose | map( {(.[0]): .[1]} ) | add" myinput.txt Commented Jan 23, 2017 at 14:30
  • The array from which I got my object keys was of the number type, I simply used .[0]|tostring inside the map (e.g. pipe to tostring) following the answer to this question Commented Jan 3, 2020 at 5:50
  • 1
    Another option to build a dict from a list of pairs is map({key: .[0], value: .[1]}) | to_entries Commented Mar 12, 2021 at 18:51