Danny pointed you to very good resources but I'm jumping in the ring for the challenge.
I'm not much of a bash coding pro and much less with jq so here's a simple bash script that will collect your hosts and networks, log them in a CSV, display in which group(s) they can be found if any then deletes the CSV. I use grep with jq as playing with the latter's syntax was breaking the mood of my Friday evening.
don't forget to chmod +x the file before running it.
I named it obj2grp but make your pick.
#!/bin/bash
mgmt_cli -r true show hosts --format json |jq -r '.objects[] | [.name] | @csv' -r > obj.csv
mgmt_cli -r true show networks --format json | jq -r '.objects[] | [.name] | @csv' -r >> obj.csv
while read line
do
a=`mgmt_cli -r true where-used name $line --format json | jq -r '."used-directly"[]' | grep name | grep -v SMC`
echo "Object $line is found in $a"
done < obj.csv
rm obj.csv
Here's a sample output.
Object "cphost-1" is found in "name": "cpgroup-1",
Object "cphost-100" is found in "name": "cpgroup-5",
Object "cphost-2" is found in "name": "cpgroup-2",
"name": "cpgroup-1",
Object "cphost-200" is found in "name": "cpgroup-5",
Object "CP_default_Office_Mode_addresses_pool" is found in
Object "cpnet_172.16.15.0-25" is found in "name": "cpgroup-4",
Object "IPv6_Link_Local_Hosts" is found in
Object "net_10.20.10.0-24" is found in "name": "cpgroup-1",
You can certainly improve it from there.