//json example
//simplest json - which is an object
// properties define something as an object, so if you can refer to //it as a dot i.e
//JSON do nothing bt define data
// Example of a book object
var aBook = {
"isbn": "94234-123A",
"title": "Of Mice and Men",
"pages": 102,
"autor": "John Steinbeck",
"languages": ["english", "french (translate)"],
"published":2006
};
//json above, but always can add properties later or replace
aBook.genre = "Southern hobo fiction";
aBook.autor = "Andrea Jimenez";
//now we have the book, lets go through and read what's inside it
//Set up a for loop, but instead of saying i=0 as before
//now use ->in<-. to declare variable (in this case key)
//then run, and view in console log
//Quick note -- the ordering is not enforece; don't expect these properties to be in the same order you put them in above
for (var key in aBook){
console.log("The Key is " + key + " and that value is " + aBook[key]);
}
//can add one object to another (nesting)
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.