mkdir -p error_folder &&
for json in ./*.json; do
if jq -e '.. | select(type == "array" and length == 0)' "$json" >/dev/null
then
mv "$json" error_folder/
fi
done
This is more or less the same approach as Roman took in his answer, but uses a different jq expression.
The expression ..|select(type == "array" and length == 0) will recurse the full JSON structure and select all bits of it that are zero-length arrays (anywhere, at any depth).
If the select() is successful, then jq will exit with a zero exit status (success), which means that the JSON document contains an empty array somewhere (or the file is totally empty). This triggers a moving of the document to error_folder in the script.
From comments below it is clear that the user is only interested in the WarehouseActivity array.
My code with a modified jq expression:
mkdir -p error_folder &&
for json in ./*.json; do
if jq -e '.. | .WarehouseActivity? | select(type == "array" and length == 0)' "$json" >/dev/null
then
mv "$json" error_folder/
fi
done
WarehouseActivitycommon/same for all the files?jq?{ "x": [[],[]] }would have an array made of two empty arrays. Should that also be flagged?