I have a json query string which has to be converted to javascript usuable data set. Please help me with a small simple javascript code.

json_text = {hash:[student_name,age,height],data:[[fathima,17,5],[ajay,16,7],[farah,19,6]]};

am able to parse the string but not able to covert it to a simple array.

share|improve this question
4  
That's not valid JSON, and unless you have variables called fathima, ajay etc it's not valid JavaScript either. – James McLaughlin Feb 26 at 16:12
2  
Please show what you tried. I don't know what it means when you say "am able to parse the string but not able to covert it to a simple array." – am not i am Feb 26 at 16:13
you're code is a javascript object , not a json string. – camus Feb 26 at 16:21
Amazes me how some people have such little interest in their own question. – am not i am Feb 26 at 17:30
feedback

closed as not a real question by am not i am, Quentin, OMG Ponies, PeeHaa, tereško Feb 26 at 20:22

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

2 Answers

As james said that is not valid JSON. Unless the variables are valid, if they are then you could parse that object into a string by doing:

var jsontext = JSON.stringify({hash:[student_name,age,height],data:[[fathima,17,5],[ajay,16,7],[farah,19,6]]});

However that will only work if the they are actually variables, if you are having trouble check out http://json.parser.online.fr/ it's a handy little tool to help you parse JSON.

share|improve this answer
feedback

First, let's assume you meant this:

var json_text = '{"hash":["student_name","age","height"],"data":[["fathima",17,5],["ajay",16,7],["farah",19,6]]}';

Now you can do something like:

var json_object = JSON.parse(json_text);

And then you can access items in it:

json_object.hash[0]     // "student_name"
json_object.data[0][0]  // "fathima"
json_object.data[1][2]  // 7
share|improve this answer
feedback

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