How to add nested object to existing json

You have to stringify the responseData before saving it to the “body” environment variable. (Like you do for the updatedBody).

Then parse it when you retrieve it.

You can parse this in one line.

let variableName = JSON.parse(pm.environment.get("body"));

If you use let or var instead of const, then you can update the elements directly.
You don’t really need to use push.

PS: This is a JavaScript object at this point.

In your example, the product.push is incorrect, as surely it should be jsonObject.info.product.

Not sure if its will a valid object after this. (Hence the error).

You can also just define the whole product element, and update it in one go. Like following.

let response = pm.response.json().data;  // parse JSON response into JavaScript object.

console.log(response); // original response.

// define product element to replace null entries
const productNull = {
    "productId": 123,
    "info": {
        "available": true,
        "restock": {
        "enabled": true
        }
    }
}

if (response.info.product ==null) {
    response.info.product = productNull // update response
}

console.log(response) // updated response - remember to stringify before saving to environment\collection variable.

image