I want to be able to parse the output from jq as json. At the moment it gives me:
{
"Name": "webserver-20130326",
"ImageId": "ami-ef9bc192",
"RootDeviceType": "ebs",
"State": "available"
}
{
"Name": "webserver-20130328",
"ImageId": "ami-4f9ac442",
"RootDeviceType": "ebs",
"State": "available"
}
{
"Name": "webserver-20130402",
"ImageId": "ami-efd341de",
"RootDeviceType": "ebs",
"State": "available"
}
What I want is the same, but with objects separated by commas:
{
"Name": "webserver-20130326",
"ImageId": "ami-ef9bc192",
"RootDeviceType": "ebs",
"State": "available"
},
{
"Name": "webserver-20130328",
"ImageId": "ami-4f9ac442",
"RootDeviceType": "ebs",
"State": "available"
},
{
"Name": "webserver-20130402",
"ImageId": "ami-efd341de",
"RootDeviceType": "ebs",
"State": "available"
}
With this output I can parse it using python's json.load() and it will allow me to work with a list of objects.
How can I make jq put a comma after each object?
Instead of doing jq 'foo', do jq '[foo]'. Wrapping a filter in square brackets causes it to output all of its results in one array, rather than one at a time.
OK thanks
Most helpful comment
Instead of doing
jq 'foo', dojq '[foo]'. Wrapping a filter in square brackets causes it to output all of its results in one array, rather than one at a time.