<script type="text/javascript">
var X = {
a: [{name:john, phone:777},{name:john, phone:777},{name:john, phone:777}],
b: [{name:john, phone:777},{name:john, phone:777},{name:john, phone:777}],
c: [{name:john, phone:777},{name:john, phone:777},{name:john, phone:777}],
d: [{name:john, phone:777},{name:john, phone:777},{name:john, phone:777}]
}
var str = JSON.stringify(X);
alert(str);
</script>
What’s wrong with this object?? It alerts “Uncaught ReferenceError: john is not defined”
How come??
You need quotes around john. Otherwise it is referring to an variable/object that has not been created:
Your code would be valid if
johnwas previously defined:Now
johnis a variable representing the string “john”, and the JSON is valid.