Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Array to Json [duplicate]

Possible Duplicate:
Serializing to JSON in jQuery
Convert Object to JSON string

I want to convert array to json object in js or jquery. Is there any function is available or lib

Thanks in advance

like image 537
sachin Avatar asked Jan 12 '12 12:01

sachin


2 Answers

In modern browsers you can simply use JSON.stringify(someJSObject) to convert any JavaScript object (that includes arrays) to a JSON string.

To ensure it also works in less modern browsers, include https://github.com/douglascrockford/JSON-js/blob/master/json2.js on your page.

like image 167
ThiefMaster Avatar answered Sep 20 '22 12:09

ThiefMaster


How about

var jsonString = JSON.stringify(myArray); 
like image 24
ladar Avatar answered Sep 21 '22 12:09

ladar