var json_data = {"2013-01-21":1,"2013-01-22":7};
var result = [];

for(var i in json_data)
    result.push([i, json_data [i]]);


var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows(result);

http://jsfiddle.net/MV5rj/

Answer from salexch on Stack Overflow
Top answer
1 of 3
54

If you have a JS array of JSON objects:

var s=['{"Select":"11","PhotoCount":"12"}','{"Select":"21","PhotoCount":"22"}'];

and you want an array of objects:

// JavaScript array of JavaScript objects
var objs = s.map(JSON.parse);

// ...or for older browsers
var objs=[];
for (var i=s.length;i--;) objs[i]=JSON.parse(s[i]);

// ...or for maximum speed:
var objs = JSON.parse('['+s.join(',')+']');

See the speed tests for browser comparisons.


If you have a single JSON string representing an array of objects:

var s='[{"Select":"11","PhotoCount":"12"},{"Select":"21","PhotoCount":"22"}]';

and you want an array of objects:

// JavaScript array of JavaScript objects
var objs = JSON.parse(s);

If you have an array of objects:

// A JavaScript array of JavaScript objects
var s = [{"Select":"11", "PhotoCount":"12"},{"Select":"21", "PhotoCount":"22"}];

โ€ฆand you want JSON representation for it, then:

// JSON string representing an array of objects
var json = JSON.stringify(s);

โ€ฆor if you want a JavaScript array of JSON strings, then:

// JavaScript array of strings (that are each a JSON object)
var jsons = s.map(JSON.stringify);

// ...or for older browsers
var jsons=[];
for (var i=s.length;i--;) jsons[i]=JSON.stringify(s[i]);
2 of 3
7
var json = jQuery.parseJSON(s); //If you have jQuery.

Since the comment looks cluttered, please use the parse function after enclosing those square brackets inside the quotes.

var s=['{"Select":"11","PhotoCount":"12"}','{"Select":"21","PhotoCount":"22"}'];

Change the above code to

var s='[{"Select":"11","PhotoCount":"12"},{"Select":"21","PhotoCount":"22"}]';

Eg:

$(document).ready(function() {
    var s= '[{"Select":"11","PhotoCount":"12"},{"Select":"21","PhotoCount":"22"}]';

    s = jQuery.parseJSON(s);

    alert( s[0]["Select"] );
});

And then use the parse function. It'll surely work.

EDIT :Extremely sorry that I gave the wrong function name. it's jQuery.parseJSON

Jquery

The json api

Edit (30 April 2020):

Editing since I got an upvote for this answer. There's a browser native function available instead of JQuery (for nonJQuery users), JSON.parse("<json string here>")

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-convert-an-object-into-array-of-objects-in-javascript
How to Convert an Object into Array of Objects in JavaScript? - GeeksforGeeks
July 23, 2025 - Object.values() method extracts the property values of an object and returns them as an array, converting the original object into an array of objects.
๐ŸŒ
Medium
saurabhnativeblog.medium.com โ€บ convert-object-of-objects-to-json-array-in-a-single-line-of-code-43b8d3f8e863
Convert Object of Objects to JSON Array in a Single Line of Code | by Saurabh Mhatre | Medium
August 16, 2024 - const jsonArray = Object.values(objectOfObjects); console.log(jsonArray); ... Extract Values: Object.values(objectOfObjects) converts the object of objects into an array of objects:
Find elsewhere
๐ŸŒ
Squash
squash.io โ€บ how-to-convert-json-object-to-javascript-array
How to Convert JSON Object to JavaScript Array - Squash Labs
Make sure to test your code with ... object to a JavaScript array can be achieved using the Object.values() method or a combination of Array.from() and Object.values()....
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Convert An Object To An Array In Javascript - YouTube
Hey guys, it's been quite a while since I last uploaded but I'm going to start uploading more tutorial-style videos, I promise! Sorry about the mic quality, ...
Published: January 24, 2023
๐ŸŒ
Js2ts
js2ts.com โ€บ home โ€บ javascript object to json converter
Object to JSON Converter โ€” JavaScript Object to JSON Online | js2ts.com
Convert JavaScript objects to valid JSON online. Paste any JS object literal, array, or nested object and get clean JSON instantly. Free, no login required.
๐ŸŒ
Medium
medium.com โ€บ @louistrinh โ€บ converting-data-structures-in-javascript-arrays-to-json-objects-fe2cfc53cdf6
Converting Data Structures in JavaScript: Arrays to JSON Objects | by Louis Trinh | Medium
December 12, 2024 - This approach allows you to define ... { color: "red", size: "medium" }, item_2: true } ... JavaScript objects are not directly convertible to arrays by default....
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ convert an object to an array in javascript
Convert an Object to an Array in JavaScript
March 29, 2020 - To convert the enumerable string-keyed properties of an object to an array, you use the Object.entries() method.
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ how-to-convert-objects-to-arrays-and-vice-versa-in-javascript-7776b5843948
How To Convert Objects to Arrays and Vice Versa in JavaScript | by Jonathan Hsu | Better Programming
November 20, 2019 - If youโ€™ve worked with data sets, especially web-based APIs, then Iโ€™m confident you have come across JavaScript Object Notation (JSON). A lightweight alternative to XML and the notation used in document-based databases such as MongoDB, JSON is everywhere. This tutorial will demonstrate how to take an object and convert it to an array and vice versa using built-in methods in the Object class.
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 76-converting-object-to-array
Converting Object to an Array | SamanthaMing.com
Finally with ES2017, it's official now! We have 3 variations to convert an Object to an Array in JavaScript
๐ŸŒ
Toolslick
toolslick.com โ€บ conversion โ€บ data โ€บ javascript object to json converter
JavaScript Object to JSON Converter - Tool Slick
JavaScript Object to JSON Converter is an online tool to convert JavaScript (JS) objects into JSON by adding double quotes to property names
๐ŸŒ
OneCompiler
onecompiler.com โ€บ javascript โ€บ 3ww4b7q6d
Convert Key, Values in an Object to Array - JavaScript - OneCompiler
Below are couple of ways to use arrow function but it can be written in many other ways as well. ... const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] const squaresOfEvenNumbers = numbers .filter((ele) => ele % 2 == 0) .map((ele) => ele ** 2) console.log(squaresOfEvenNumbers) ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript-convert-an-array-to-json
Convert an Array to JSON in JavaScript | GeeksforGeeks
October 7, 2024 - These objects are quite different from JavaScriptรขย€ย™s primitive data types (Number, String, Boolean, null, undefined, and symbol). Methods to convert the Objects to JavaScript Array:1. Using Obje ... You have a number, like 12345, and you need to convert it into an array where each element represents a digit of the number.