JSON Examples

Get Data from a JSON File


Get my Resume that is stored in a JSON file


  • Get Resume from JSON button is pressed. Runs JavaScript JSON_Jeff_Resume.js
  • JSON input file is located in JeffResume.json
  • $.getJSON(file, function(data) - JQuery command loads JSON-encoded data from the server using a GET HTTP request.
  • $("#resume_result").append - JQuery command to Insert content, specified by the parameter,to the end of each element in the set of matched elements.
  • Context is loaded in the id="resume_result" div area in the HTML
  • Click the RESET button to clear the page.


Create Object from JSON String



Here is the hardcoded JSON string in the Javascript function:

var text = '{"employees":[' + '{"firstName":"John","lastName":"Doe" },' + '{"firstName":"Anna","lastName":"Smith" },' + '{"firstName":"Peter","lastName":"Jones" }]}';

Data will be displayed below the button after you press it.






Get Data from a JSON File # 2


Here is what the JSON file that's being read looks like:

[
{
"name" : "Apple",
"color" : "red",
"origin": "U.S."
},
{
"name" : "Orange",
"color" : "orange",
"origin": "U.K."
},
{
"name" : "Strawberry",
"color" : "red",
"origin": "Japan"
}
]