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

Convert sequence of JSON lines (JSONL) to JSON array

$
0
0

I have a file where each line is a JSON object. I'd like to convert the file to a JSON array.

The file looks something like this:

{"address":"email1@foo.bar.com", "topic":"Some topic."}{"address":"email2@foo.bar.com", "topic":"Another topic."}{"address":"email3@foo.bar.com", "topic":"Yet another topic."}

I'm using bash and jq.

I tried

jq --slurp --raw-input 'split("\n")[:-1]' my_file

But that just treats each line as a string creating a JSON array of strings.

["{\"address\":\"email1@foo.bar.com\", \"topic\":\"Some topic.\"}","{\"address\":\"email2@foo.bar.com\", \"topic\":\"Another topic.\"}","{\"address\":\"email3@foo.bar.com\", \"topic\":\"Yet another topic.\"}"]

I'd like to have:

[  {"address":"email1@foo.bar.com", "topic":"Some topic."},  {"address":"email2@foo.bar.com", "topic":"Another topic."},  {"address":"email3@foo.bar.com", "topic":"Yet another topic."}]

Viewing all articles
Browse latest Browse all 657

Trending Articles



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