Ajax: Parsing and Reading JSON files
How to parse and read json files in AJAX
A sample JSON file will be similar to something like this:
This could be a sample JSON file. Now let us see how can we parse and read the contents from JSON file and print only the content that we wants. In the modern day browsers, parsing JSON is very simple. Modern browsers supports parse command which can be used to Parse a JSON file and save it to a variable. Let us see how can we do this:
Parsing JSON is as simple as above. All most all modern browsers will support JSON.parse method so parsing JSON is much simpler now a days.. Now let us see how we can print the result in a list:
This will add the parsed JSON elements to the webpage. Even though Ajax was originally designed to work with XML files, it can work with JSON and other formats as well and sometimes the process is simpler than processing XML. As you can see here, parsing and reading JSON was much simpler than XML.