How to avoid to adding some characters when adding a new item in JSON with Java Script

I’m trying to add a new item to JSON with the following code ;

var obj = JSON.parse(jsoncontent);
        
obj["subnets"]["values"].push('{"gateway": "2.2.2.2","prefixLength": 24,"dnsSuffix": null,"dnsServer1": "","dnsServer2": "","ipRanges":.... .bla bla bla');
    
Alert(JSON.stringify(obj,null,'t'));

But, as you can see at below, new items is adding with “” and “” characters. How can I avoid this ?

{
    "gateway": "1.1.1.1",
    "prefixLength": 24,
    "dnsSuffix": null,
    "dnsServer1": "",
    "dnsServer2": "",
    "ipRanges": {
        "values": []
    },
    "enabled": false,
    "totalIpCount": 0,
    "usedIpCount": null,
    "primaryIp": null,
    "autoAllocateIpRanges": false
},
"{  "gateway": "2.2.2.2",  "prefixLength": 24,  "dnsSuffix": null,  "dnsServer1": "",  "dnsServer2": "",  "ipRanges": {    "values": []  },  "enabled": false,  "totalIpCount": 0,  "usedIpCount": null,  "primaryIp": null,  "autoAllocateIpRanges": false}"

Answer

In your push function, you append a string instead of an object. Try to remove quotes around this object.

obj["subnets"]["values"].push({"gateway": "2.2.2.2","prefixLength": 24,"dnsSuffix": null,"dnsServer1": "","dnsServer2": ""});