Skip to content

Instantly share code, notes, and snippets.

@jamc92
Created February 24, 2015 05:10
Show Gist options
  • Save jamc92/42bca850d66281c4a11d to your computer and use it in GitHub Desktop.
Save jamc92/42bca850d66281c4a11d to your computer and use it in GitHub Desktop.
JS - jSON html
<!DOCTYPE html>
<html>
<head>
<title>JSON practice</title>
<script src="json.json"></script>
</head>
<body>
<script>
//Access to information in json object
document.write('Javier is ' + jason.age);
document.write(jason.address);
document.write(jason.lastname);
//Access to information in a JSON array
//We scope to the array, its position and name.
document.write(brothers[0].name);
document.write(brothers[1].gender);
//Access to nested JSON data
document.write(parents.mother.name);
document.write(parents.father.name);
</script>
</body>
</html>
//Creating my jason object
var jason = {
"age" : "22",
"address" : "Caracas",
"lastname" : "Madrid"
};
//Storing JSON data in an array
var brothers = [
{
"name" : "Javier",
"age" : "22",
"gender" : "male"
},
{
"name" : "Alejandra",
"age" : "34",
"gender" : "female"
},
{
"name" : "Juan",
"age" : "37",
"gender" : "male"
},
{
"name" : "Caupolican",
"age" : "38",
"gender" : "male"
}
]
//Nesting JSON data
var parents = {
"mother" : {
"name" : "Mom",
"age" : "50+"
},
"father" : {
"name" : "Dad",
"age" : "60+"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment