JaviOverflow
JaviOverflow

Reputation: 1480

How can I process oneline json files using `jq`

I have a onelined json file that looks similar to this

{"fieldA":1, "fieldB":"foo"}
{"fieldA":2, "fieldB":"bar"}
{"fieldA":4, "fieldB":"foobar"}
...

How can I properly read this file using jq?

I tried doing:

cat myFile.json | jq [.]

but this returns something like:

[{
  "fieldA":1, 
  "fieldB":"foo"
}]
[{
  "fieldA":2, 
  "fieldB":"bar"
}]
[{
  "fieldA":4, 
  "fieldB":"foobar"
}]
...

but I would like to receive this instead:

[{
  "fieldA":1, 
  "fieldB":"foo"
},
{
  "fieldA":2, 
  "fieldB":"bar"
},
{
  "fieldA":4, 
  "fieldB":"foobar"
},
...]

Thanks in advance!

Upvotes: 0

Views: 175

Answers (1)

hobbs
hobbs

Reputation: 239732

Are you sure you want that? What's your end goal? You can merge all of the inputs into a single array using jq -n '[inputs]' (the -n avoids the usual reading of stdin into ., allowing it all to appear on inputs), but that means that it can't produce any output, or do any further processing, until the entire input has been read, which may or may not be what you want.

Upvotes: 1

Related Questions