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

Updating a nested object in json and saving it back to original

$
0
0

I have big json, where i am renaming a nested object .module.home.[].list member from object_old to object_new and then deleting the object_old key.

cat out.json{    ...    {"objecta": {"field1": 1,"field2": 2    },"objectb": {"field1": 1,"field2": 2    },"object_old": {"field1": 1,"field2": 2    }    }    ...}jq ".module.home.[].list | .object_new = .object_old | del(.object_old)" out.json{"objecta": {"field1": 1,"field2": 2  },"objectb": {"field1": 1,"field2": 2  },"object_new": {"field1": 1,"field2": 2  }}

Now, while i was able to update .module.home.[].list, i only have the updated sub object in the output. How can i get the entire json back with the updated object_new, so i can save it back to out.json


Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>