up vote 1 down vote favorite

Possible Duplicate:
How to count JavaScript array objects?

If it's not a JavaScript array, so how to convert it into JSON array?

var member = {
    "mother": {
        "name" : "Mary",
        "age" : "48"
    },
    "father": {
        "name" : "Bill",
        "age" : "50",
        "friend": {
          "co-worker" : "Jake"
        }
    },
    "brother": {
        "name" : "Alex",
        "age" : "28"
    }
}
flag

2  
Duplicate: stackoverflow.com/questions/2693021/… – Nerdling Apr 22 at 17:47
It's not a duplicate! – Nikita Sumeiko Apr 22 at 17:53
I am not sure what you mean. Are you trying to change it into a dictionary/associative array? – jdangel Apr 22 at 17:59

closed as exact duplicate by Vivin Paliath, womp, Pim Jager, Anthony Forloney, bmargulies Apr 23 at 1:54

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question.

2 Answers

up vote 1 down vote

There's a plugin for jQuery.

link|flag
up vote 1 down vote

Javascript object and array literals are near-as-much identical to their JSON counterparts - JSON is just a bit more strict. Where this

{prop:"value"}

Is valid javascript, JSON requires double-quotes around property names, like so

{"prop":"value"}

So, with that in mind, what you have posted above actually is JSON (less the var member = bit, since JSON just a data format).

There is no magic "convert to array" function that will help you. If you want this data as an array, that's possible, but the exact structure of that resulting array will be specific to the needs of your application - that's not something we can guess.

Do you have an idea of what you want the resulting array to look like?

link|flag

Not the answer you're looking for? Browse other questions tagged or ask your own question.