I'm fairly new to JSON and I currently have a list of ~130 JSON files that I received by downloading my Facebook message data. I'm currently attempting to use JQ To concatenate them all into a single json file while keeping the existing message order intact however I'm running into errors when I attempt to enter commands on Windows. I have attempted to follow their suggestions for Windows within the FAQ and am still running into issues.
All files have the same layout
{
"participants": [
{
"name": "Participant One"
},
{
"name": "Participant Two"
}
],
"messages": [
{
"sender_name": "Participant One",
"timestamp_ms": 99999999999,
"content": "message content",
"type": "Generic"
},
{
"sender_name": "Participant Two",
"timestamp_ms": 9999999999,
"content": "message content",
"type": "Generic"
}
],
"title": "chat title",
"is_still_participant": true,
"thread_type": "Regular",
"thread_path": "thread path"
}
If possible with JQ, I'd like to combine only the "messages" into a single JSON file while keeping them in the existing order. The messages are the only data in these files that I care about for my purposes.
--Edit-- Very sorry for the lack of details in the original post. I've attempted several commands that I've found both on here and elsewhere:
jq -s "[.[][]]" a-*.json > output.json
jq -s "{ attributes: map(.attributes[0]) }" file*.json > output.json
jq -s "*" *.json > output.json
I've also attempted to put this code into a text file and rune it using: jq -f filename But am also receiving errors
The errors I've been getting are either:
jq: error: Could not open file *.json: Invalid argument
or
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Windows cmd shell quoting issues?) at <top-level>
As for more specifics on the output I'm trying to achieve: I am using JQ 1.5. I don't care about the order that the JSON files get added to one another as long as the messages remain in the correct order so that I can get clear defined message/response pairs. I also don't care if it all gets combined and I have to separate out the messages in a different way. Something along the lines of this would be my ideal output:
"messages": [
{
"sender_name": "Participant One",
"timestamp_ms": 99999999999,
"content": "message content",
"type": "Generic"
},
{
"sender_name": "Participant Two",
"timestamp_ms": 9999999999,
"content": "message content",
"type": "Generic"
},
{
"sender_name": "Participant Three",
"timestamp_ms": 9999999999,
"content": "message content",
"type": "Generic"
},
{
"sender_name": "Participant Two",
"timestamp_ms": 9999999999,
"content": "message content",
"type": "Generic"
}
]
Where participant two represents my responses to messages and other participants are the people I am having conversations with (Which is how it is in the original JSON output from Facebook)