Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

How can I modify a specific object structure at any location in a larger JSON object using `jq`?

$
0
0

Say I have this JSON:

{"lunch": {"time": "11 am","food": {"is_pizza": true    }  },"snacks": [    {"time": "2 pm","food": {"is_pizza": true      }    },    {"time": "3:30 pm","food": {"is_pizza": true      }    }  ],"dinner": {"time": "6 pm","food": {"is_pizza": true    }  }}

Now I want to go through and wherever I see "food" object, add a the same key-value pair:

{"lunch": {"time": "11 am","food": {"is_pizza": true,"extra_cheese": true    }  },"snacks": [    {"time": "2 pm","food": {"is_pizza": true,"extra_cheese": true      }    },    {"time": "3:30 pm","food": {"is_pizza": true,"extra_cheese": true      }    }  ],"dinner": {"time": "6 pm","food": {"is_pizza": true,"extra_cheese": true    }  }}

How can I do that in jq?


Viewing all articles
Browse latest Browse all 527

Trending Articles