Convert json to string using jquery

I have a nested json. I want to publish it as input form value.

But it seems that jquery puts the string "Object object" in the value.

It seems easier to pass the string and convert it to the form I need, than to deal with json, since I don't need to change anything after creating it.

What is the easiest way to convert json

 var json = { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ], "newSubscription": false, "companyName": null }; 

in its lowercase form?

 var json = '{ "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ], "newSubscription": false, "companyName": null }' 

The following does not do what I need:

 Json.stringify() 
+7
json javascript jquery
source share
1 answer

jQuery does not have a method for JSON building its own objects. You will need json2.js , which will provide the JSON.stringify() method for browsers that do not yet support it.

+12
source share

All Articles