JSON (JavaScript Object Notation) is the standard design for human-readable data interchange. It is a light-weight, human-readable format used for storing and transporting data. Since JSON works with a tree structure, it looks like an
There are several online websites that contain JSON data in order to test and apply their algorithms. I will test one such algorithm on JSON data. In JavaScript, there are several methods to read JSON data through a URL such as jqeury, loadJSON methods, etc. In this shot, we’ll look at a simple loadJSON method for better understanding.
userId
, id
, title
, and body
. The id
field represents the post number..js
file. The loadJSON
function is a user-defined method that initiates a new XMLHttpRequest whenever the function is called. This function then checks the status and state of the URL provided to confirm the validity of the JSON data. If there are no errors, parsed JSON data is returned.The loadJSON
function has three parameters:
loadJSON("https://jsonplaceholder.typicode.com/posts",myData,'jsonp');
myData
. As you can see below, the function has a Data
parameter. The data read from the website URL is sent to this function in the Data
parameter. In this example, we are defining the function to just output the details about the first post:function myData(Data)
{
console.log(Data[0]);
}