0

I have user.txt log file which have this data below and I want to convert it in json format.

{"user":"Demo Admin","user_id":"57c4718434243dc47d8b456c","org_id":"57c4718434243dc47d8b456b","superuser_id":null,"superuser_name":null,"application":"Trackier Webapp","method":"GET","ip":"43.249.54.66","domain":"demo.trackier.com","url":"https:\/\/demo.trackier.com\/admin.html","created":"2022-09-08 06:19:18","@timestamp":"2022-09-08T06:19:18Z"}
{"user":"Demo Admin","user_id":"57c4718434243dc47d8b456c","org_id":"57c4718434243dc47d8b456b","superuser_id":null,"superuser_name":null,"application":"Trackier Webapp","method":"GET","ip":"43.249.54.66","domain":"demo.trackier.com","url":"https:\/\/demo.trackier.com\/admin.html","created":"2022-09-08 06:19:35","@timestamp":"2022-09-08T06:19:35Z"}
αғsнιη
  • 41,407
wasim
  • 1
  • 1
  • 2

1 Answers1

5

Assuming you want to convert that file with one json per line to one json array, you could do:

sed '1s/^/[/;$s/$/]/;$!s/$/,/' < file.multijson > file.json

Which inserts [ at the start of the first line, ] at the end of the last line, and , at the end of all but the last line.

If you have jq, you can also do:

jq -s < file.multijson > file.json

(add -c to get a compact form), but beware it may reformat numbers (like change 1e1 or 10.0000000000000001 to 10) or strings (like change "\u00e9" to "é").