1// Array to JSON:
2const jsonString = JSON.stringify(yourArray);
3// JSON to Object / Array
4const yourData = JSON.parse(jsonString);
1var arr = [ "John", "Peter", "Sally", "Jane" ];
2var myJSON = JSON.stringify(arr);
1var person={"first_name":"Tony","last_name":"Hawk","age":31};
2var personJSONString=JSON.stringify(person);
1const myObj = {
2 name: 'Skip',
3 age: 2,
4 favoriteFood: 'Steak'
5};
6
7const myObjStr = JSON.stringify(myObj);
8
9console.log(myObjStr);
10// "{"name":"Skip","age":2,"favoriteFood":"Steak"}"
11
12console.log(JSON.parse(myObjStr));
13// Object {name:"Skip",age:2,favoriteFood:"Steak"}
1var jsonPerson = '{"first_name":"billy", "age":23}';
2var personObject = JSON.parse(jsonPerson); //parse json string into JS object
1var json_data = {"2013-01-21":1,"2013-01-22":7};
2var result = [];
3
4for(var i in json_data)
5 result.push([i, json_data [i]]);
6
7
8var data = new google.visualization.DataTable();
9data.addColumn('string', 'Topping');
10data.addColumn('number', 'Slices');
11data.addRows(result);
12