I have a function that checks for duplicate values held within objects inside a json file. When duplicates are found the function returns something like this:
{
"Basket1": [
Apple,
Orange
],
"Basket2": [
Apple,
Orange
]
}
If no duplicates are found then it returns am empty list:
{}
Currently I am using -s in bash like such to check if the there are dups found within the output:
<"$baskets" jq -L $HOME 'check_dups' > "$dups"
if [[ ! -s "$dups" ]];
then
echo -e "${RED}[Error]${NC} Duplicates found! Please review duplicates below" >&2
echo "$(cat "$dups" | jq '.')"
else
echo -e "${GREEN}[SUCCESS]${NC} No duplicates found" >&2
fi
However empty object returned if no dups are found will cause the -s file check in bash to succeed regardless. What would be the best way using jq or bash to check whether the output of this function is an empty object or not?