-4

I tried to parse my json data and put it in single array but got no luck. I tried the answers in this link How to convert JSON object to JavaScript array but still not the exact result that i wanted.

here's my json

{
  "Sheet1": [
    {
      "code": "00011",
      "name": "Test 1"
    },
    {
      "code": "00082",
      "name": "Test 2"
    },
    {
      "code": "00083",
      "name": "Test 3"
    }
   ]
}

and i want to put it in one array. The result should be like the code below.

var myarray = [{"code": "00011", "name": "test 1"},{"code": "00082", "name": "test 2"},{"code": "00083", "name": "test 3"}];
Community
  • 1
  • 1
sse
  • 47
  • 1
  • 10
  • 4
    `var myarray = myParsedJson.Sheet1;`…?! – deceze Oct 26 '16 at 12:54
  • Possible duplicate of [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Liam Oct 26 '16 at 12:55

1 Answers1

1

I'm assuming you've got the json as a string within your javascript? Something like:

var json = '{"Sheet1": [{"code": "00011","name": "Test 1"},{"code": "00082","name": "Test 2"},{"code": "00083","name": "Test 3"}]}';

If that's the case first parse the json, which will turn it into an object literal:

var parsed = JSON.parse(json);

You can then access the array you want, as shown below:

var myarray = parsed.Sheet1;
ArranJacques
  • 814
  • 3
  • 9
  • 9