how to convert json array to javascript array

advertisements

I have below json array

`[{"name":"The Shawshank Redemption","rating":"9.3","year":"1994","stars":["Tim Robbins","Morgan Freeman","Bob Gunton"],},{"name":"The Godfather","rating":"9.2","year":"1972","stars":["Marlon Brando","Al Pacino","James Caan"]}]`

I want to convert in javascript array and print as html. then I would copy the array and save in .js file like below. problem is how to remove the inverted coma from "name" to name

var Movies =  [ { name: 'The Shawshank Redemption',
rating: '9.3',
year: '1994',
stars:
 [ 'Tim Robbins',
   'Morgan Freeman',
   'Bob Gunton' ]},
{ name: 'The Godfather',
rating: '9.2',
year: '1972',
stars:
 [ 'Marlon Brando',
   'Al Pacino',
   'James Caan' ]}
];


var movies= $.parseJSON(myStr); put your string in it

for printing

var newAry=[];
$.each(movies,function(i,v){
  newAry.push(JSON.stringify(v));
});

$( '#div' ).html(newAry);