I've below JSON, I want to parse all these key names product, inventory, rating, review dynamically and put it in the list and iterate the key name one by one.
{
"product": [
{
"productID": "123",
"productName": "test1"
}
],
"inventory": [
{
"id": "12093",
"name": "adie"
}
],
"rating": [
{
"value": "4",
"status": "done"
}
],
"review": [
{
"desc": "good",
"comments": "test"
}
]
}
After parsing the key name dynamically, I want to form all the key name in a comma separated and assigned to key_list variable like below:
key_list="product,inventory,rating,review"
After that I want to iterate key_list in a loop and print them or do something with that value. The desired output would be print the key name one by one in a loop:
product
inventory
rating
review
How can we achieve this using shell script jq?
key_listis your output or your input? None of this is hard to do in jq (and it's all possible in jq alone -- no need to lean on the shell for any of the logic), but I'm not clear what your desired outcome is. Maybe show desired output, not just your inputs? (You want to iterate over the keys in the list and do what with them?)