-1

i have the following Json Data with following format...

var oData = [
{           
    "0":
    {
        "firstname": "aaa",
        "lastname": "zzz",
         "Email": "aaa@test.com"
    },

    "1":
    {
        "firstname": "bbb",
        "lastname": "yyy",
        "Email": "bbb@test.com"
    },

    "2":
    {
        "firstname": "ccc",
        "lastname": "www",
        "Email": "ccc@test.com"
    }

}];

Can we convert to the following format ??

var rData = [              
    {
        "firstname": "aaa",
        "lastname": "zzz",
        "Email": "aaa@test.com"
    },

    {
        "firstname": "bbb",
        "lastname": "yyy",
        "Email": "bbb@test.com"
    },

    {
        "firstname": "ccc",
        "lastname": "www",
        "Email": "ccc@test.com"
    }];
sheepez
  • 936
  • 1
  • 10
  • 25
  • You can convert a Jobject (the first one) into a jArray but you are going to have to read it out yourself and rebuld it. There is no way that i know of to automaticly convert them. – DaImTo Sep 19 '13 at 13:39
  • Sort of a duplicate of: http://stackoverflow.com/questions/3865139/cast-javascript-object-to-array-how-to – Orbling Sep 19 '13 at 13:48
  • 1
    By using which programming language you want to convert it? – Mr_Green Sep 19 '13 at 14:10
  • The answer to your question is "yes". But is that all you really wanted to know? – Brian Cain Sep 19 '13 at 14:13
  • Since you haven't specified a language you'll have to use a text editor and do it manaually... – Kris Sep 19 '13 at 14:14

1 Answers1

1
    var oData = [{           
        "0":
        {
            "firstname": "aaa",
            "lastname": "zzz",
             "Email": "aaa@test.com"
        },

        "1":
        {
            "firstname": "bbb",
            "lastname": "yyy",
            "Email": "bbb@test.com"
        },

        "2":
        {
            "firstname": "ccc",
            "lastname": "www",
            "Email": "ccc@test.com"
        }

    }],
    data = oData[0],
    rData = [];
JSON.stringify( data, function( key, value ) {
    rData.push( value );
});
console.log( rData );
Yuan Zhaohao
  • 544
  • 5
  • 4