Created
April 29, 2021 14:36
-
-
Save Lotti/96ea31bc5ca1d022b0ec626ed4f31666 to your computer and use it in GitHub Desktop.
script to split array of objects in separated file. bash, input: json file, output: json files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE=discovery-insurance.json | |
FOLDER=docs-insurance | |
rm -Rf "./${FOLDER}" | |
ROWS=$(jq '.results | length' "./${FILE}") | |
if [[ "${ROWS}" -eq "0" ]]; then | |
echo "ARRAY WITH ZERO ELEMENTS. EXIT." | |
break | |
fi | |
mkdir -p "./${FOLDER}" | |
PATH_NAME="./${FOLDER}/" | |
for ((i = 0 ; i < ROWS ; i++ )); do | |
fullfile=$(jq --raw-output '.results['"${i}"'].id' "./${FILE}") | |
filename=$(basename -- "$fullfile") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
jq '.results['"${i}"'] | del(.id, .result_metadata, .enriched_text, .extracted_metadata, .enriched_description, .enriched_operator_notes)' "./${FILE}" > "${PATH_NAME}${filename}.json" | |
# jq '.results['"${i}"'] | del(.id, .result_metadata)' "./${FILE}" > "${PATH_NAME}${filename}.json" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment