convert json to array via javascript
javascript, json
Solution
var sampleData = [], results = d.results;
for (var i = 0, len = results.length; i < len; i++) {
var result = results[i];
sampleData.push({ name: result.Name, Age: result.Age, Sex: result.Sex });
}
Problem
Possible Duplicate: JSON to javaScript array Can anybody point me out how i can convert a json data to an array using java script in order to draw a chart from de data. The JSON is structured as follows: ``` { "d":{ "results":[ { "_metadata":{ "uri": "http://www.something.com/hi", "type" : "something.preview.hi" }, "Name", "Sara", "Age": 20, "Sex" : "female" }, "_metadata":{ "uri": "http://www.something.com/hi", "type" : "something.preview.hi" }, "Name", "James", "Age": 20, "Sex" : "male" } ] } } ``` I would like to convert this jason to the following format: ``` var sampleData = [ { name: 'Sara', Age: 20, Sex: 'female'}, { name: 'James', Age: 20, Sex: 'male'} ]; ``` Does anyone have any advice on how to achieve this?