This commit is contained in:
Sebastian
2024-09-24 08:28:11 +02:00
parent 7f9d5200ef
commit 75d06ef967

View File

@@ -9,7 +9,22 @@ fi
BASEPATH="$(dirname "$0")" BASEPATH="$(dirname "$0")"
JSON_FILE="$BASEPATH/reference-rpc-endpoint.json" JSON_FILE="$BASEPATH/reference-rpc-endpoint.json"
shift
# Extract values under 'default' or 'archive' attributes for given keys # Function to extract values for a given key
jq --argfile input "$JSON_FILE" '. as $in | ($IN.input | select(has("default")) | .default[]) + ($IN.input | select(has("archive")) | .archive[])' "$@" extract_values() {
local key=$1
cat "$JSON_FILE" | jq -r --arg key "$key" '.[$key] | .default? // .archive? // [] | .[]'
}
# Initialize an empty result string
result=""
# Iterate over each key passed as a parameter
for key in "$@"; do
# Append the values from the key to the result string
values=$(extract_values "$key")
result="$result $values"
done
# Trim and display the result
echo $result | xargs