У меня есть несколько JSON файлов одинаковой формы, вот два примера:
message_1. json
{
"participants": [
{
"name": "Person One"
},
{
"name": "Person Two"
}
],
"messages": [
{
"sender_name": "Person One",
"timestamp_ms": 0002,
"content": "Text2.",
"type": "Generic"
},
{
"sender_name": "Person Two",
"timestamp_ms": 0001,
"content": "Text1.",
"type": "Generic"
}
],
"title": "Person One",
"is_still_participant": true,
"thread_type": "Regular",
"thread_path": "inbox/SomeString"
}
message_2. json
{
"participants": [
{
"name": "Person One"
},
{
"name": "Person Two"
}
],
"messages": [
{
"sender_name": "Person Two",
"timestamp_ms": 0004,
"content": "Text4.",
"type": "Generic"
},
{
"sender_name": "Person One",
"timestamp_ms": 0003,
"content": "Text3.",
"type": "Generic"
}
],
"title": "Person One",
"is_still_participant": true,
"thread_type": "Regular",
"thread_path": "inbox/SomeString"
}
Можно ли использовать jq
для объединения файлов JSON, чтобы атрибут messages
был объединен (порядок не имеет значения), а остальные остались одни?
Результат слияния message_1. json и message_2. json будет выглядеть следующим образом:
messages. json
{
"participants": [
{
"name": "Person One"
},
{
"name": "Person Two"
}
],
"messages": [
{
"sender_name": "Person One",
"timestamp_ms": 0002,
"content": "Text2.",
"type": "Generic"
},
{
"sender_name": "Person Two",
"timestamp_ms": 0001,
"content": "Text1.",
"type": "Generic"
},
{
"sender_name": "Person Two",
"timestamp_ms": 0004,
"content": "Text4.",
"type": "Generic"
},
{
"sender_name": "Person One",
"timestamp_ms": 0003,
"content": "Text3.",
"type": "Generic"
}
],
"title": "Person One",
"is_still_participant": true,
"thread_type": "Regular",
"thread_path": "inbox/SomeString"
}
У меня 11 JSON файлов, message_1 . json, ..., message_11. json. Я хотел бы объединить их в один messages.json
файл этой формы, содержащий все сообщения в файлах JSON. Как я могу сделать это, используя jq
через bash?