Joe Doe Joe Doe - 10 months ago 96
Javascript Question

JSON array javascript

I am using json_parse from

I need to store 3 pet names in
format, parse them into array and later read one by one


pets = '{{"name":"jack"},{"name":"john"},{name:"joe"}}';

var arr = JSON.parse(pets);


But it doesn't work.

Also I would need to add entry to array (probably with push) but I am having problems too.

Someone has idea how to do it?

Answer Source

Your JSON is malformed. Try this:

var pets = '{"pets":[{"name":"jack"},{"name":"john"},{"name":"joe"}]}';
var arr = JSON.parse(pets);