Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Flatten a JSON document using jq

$
0
0

I'm considering the following array of JSON objects:

[  {"index": "index1","type": "type1","id": "id1","fields": {"deviceOs": ["Android"      ],"deviceID": ["deviceID1"      ],"type": ["type"      ],"country": ["DE"      ]    }  },  {"index": "index2","type": "type2","id": "id2","fields": {"deviceOs": ["Android"      ],"deviceID": ["deviceID2"      ],"type": ["type"      ],"country": ["US"      ]    }  }]

and I would like to flatten it to get:

[  {"index": "index1","type": "type","id": "id1","deviceOs": "Android","deviceID": "deviceID1","country": "DE"  },  {"index": "index2","type": "type","id": "id2","deviceOs": "Android","deviceID": "deviceID2","country": "US"  }]

I'm trying to work with jq but I fail to flatten the "fields". How should I do it? At the moment I'm interested in command-line tools, but I'm open to other suggestions as well.


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>