Jq: Option to return objects as a list of objects (separated by a comma)

Created on 14 May 2013  路  2Comments  路  Source: stedolan/jq

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?

support

Most helpful comment

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.

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings