I have the following json data:
{"Country": "India","States": [ {"Name": "TN","Cities": ["city1","city2" ] }, {"Name": "KL","Cities": ["city3","city4" ] } ]}
jq expression:
{ country:.Country,states: .States | ( foreach .[] as $item (0; { name:$item.Name, city:$item.Cities } ) )}
I get the following output:
{"country": "India","states": {"name": "TN","city": ["city1","city2" ] }}{"country": "India","states": {"name": "KL","city": ["city3","city4" ] }}
I don’t want the country to be repeated two times. The main requirement is to change the key names, like city
instead of Cities