If you just want to look at it for debugging purposes, execute console.log(myObject) or console.dir(myObject) and look at the firebug / chrome / safari panel.
An object does not automatically have a length property, because it is not an array. To iterate over the properties of an object, do the following:
for (var p in location) { console.log(p + " : " + location[p]); }
In some cases, you may need to iterate over the properties of an object, but not the properties of a prototype object. If you get unnecessary stuff with a regular loop ... use Object.prototype hasOwnProperty :
for (var p in location) if (location.hasOwnProperty(p)) { console.log(p + " : " + location[p]); }
The thing is, if it is / really JSON data, at some point it should have been a string, since JSON is by definition a string representation of an object. So your question "How to print json data" almost reads like "How to print a string." If you want to print it, you have to catch it before it gets to the point that it is taken apart, and just print it.
Dagg nabbit
source share