Reputation: 2102
I have the following Json:
[{
"_id": {
"$oid": "59c3942baeef22b03fa573d2"
},
"client_id": "[email protected]",
"name": "Windows Client"
},
{
"_id": {
"$oid": "59c3942baeef22b03fa573d2"
},
"client_id": "[email protected]",
"name": "Linux Client"
}]
I would like to output the following:
mongo_customers,[email protected]
mongo_customers,[email protected]
I've tryed the following but it doesn't work:
jq -n -R \
--slurpfile mongo mongo.json \
'
$mongo[][].client_id] as $mongo_ids
"mongo_customers,customer="($mongo_ids)
'
How I can do that?
Upvotes: 4
Views: 475
Reputation: 116740
jq -r '.[] | "mongo_customers,customer=\(.client_id)"' mongo.json
There are many other possibilities. If you want to be absolutely sure the result will be valid CSV, then you might want to use the @csv
filter.
Upvotes: 6