У меня есть файл, где каждая строка является JSON объектом. Я хотел бы преобразовать файл в массив JSON.
Файл выглядит примерно так:
{"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."}
Я использую bash и jq.
Я пытался
jq --slurp --raw-input 'split("\n")[:-1]' my_file
Но это просто обрабатывает каждую строку как строку, создавая массив строк JSON.
[
"{\"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.\"}"
]
Я бы хотел получить:
[
{"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."}
]