From a81a7849c83039dba895fecdfb881d02c20ba45c Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 7 Jan 2024 22:33:28 +0100 Subject: [PATCH] create .all.json from all .rss.json in directory --- tools/json_dir.all.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 tools/json_dir.all.sh diff --git a/tools/json_dir.all.sh b/tools/json_dir.all.sh new file mode 100755 index 00000000..8c97ab29 --- /dev/null +++ b/tools/json_dir.all.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# GET AND COMBINE ALL JSON IN DIRECTORY +DIR="$1" + +## COMBINE ALL JSON +json_array=() +# Loop through each *.rss.json file and append its content to the array +for file in ${DIR}/*.rss.json; do + # Use jq to extract the JSON array from each file + data=$(jq '.' "$file") + json_array+=("$data") +done +temp_file=$(mktemp) +printf '%s\n' "${json_array[@]}" > "$temp_file" +# Use jq to read the array from the temporary file and create the merged JSON +jq -n --slurpfile array "$temp_file" '{"data": $array}' > ${DIR}/.all.json +# Remove the temporary file +rm "$temp_file"