First you forgot to put ;
at the end of $.parseJSON(myyVar)
:
var myyVar = {title: 'myTitle',root: {id:'1',title:'CEO',subtitle:'John Doe',children: [{ id: '2',title: 'COO',subtitle: 'Steve Berman',type: 'staff'},{ id: '3',title: 'CTO',subtitle: 'Mark Claskov',type: 'staff'},]}};
Second your main variable myyVar
is the one you must use in $.parseJSON()
and not myvar
:
$.parseJSON(myyVar);
And lastly, you can correct improper json format
:
var myyVar = {title: 'myTitle',root: {id:'1',title:'CEO',subtitle:'John Doe',children: [{ id: '2',title: 'COO',subtitle: 'Steve Berman',type: 'staff'},{ id: '3',title: 'CTO',subtitle: 'Mark Claskov',type: 'staff'},]}};
var newVar = JSON.stringify(myyVar );
alert($.parseJSON(newVar));
Check the fiddle. [try to change alert()
to console.log()
to see what's going on thru browser's console]