Skip to content

Convert JSON logs into an array

Last updated:

You have log files were each line is a string in JSON format and you would like to convert them into an array for further analysis in the CLI, e. g. with a tool lie fx.

Lets say we have

debug.log
{"id": 1}
{"id": 2}

Then, using sed in the terminal:

Terminal window
$ sed -e $'1s/^/[\\\n/; $!s/$/,/; $s/$/\\\n]/' c.json
[
{"id": 1},
{"id": 2}
]