Most of the web services are switching from XML to JSON data for their results. Learn how you can easily use json data in your web applications.
JSON stands for JavaScript Object Notation. In simple terms JSON is a way of formatting data for, e.g., transmitting it over a network.
You will learn a few ways to load JSON data in your web applications.
You can use plain javascript request to get json data from a URL.
Below is a simple javascript json function:
var getJSON = function(url, callback)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function()
{
var status = xhr.status;
if (status === 200)
{
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
To use this json function, just call it like this:
getJSON( 'https://randomuser.me/api/' ,function(err, data)
{
console.log(data);
})
You can also use jquery getjson function like this:
$.getJSON('https://apimk.com/ip.json' , function(data)
{
console.log(data);
});
You can also user jquery ajax function to get your url data like this:
$.ajax({
url: 'https://ghibliapi.herokuapp.com/films',
type: 'GET',
dataType: 'json',
})
.done(function(data) {
console.log("success", data);
})
.fail(function(data)
{
console.log("error");
});
These json functions will definitely come in handy in your web applications to get json data from a url.
You spend weeks building a project.
Your client pays you.
Then the income stops.
Meanwhile, other developers are turning similar skills into products that generate revenue month after month.
A SaaS, plugin, web app, or digital product can continue bringing in customers long after it's launched.
The real question isn't whether you can build one.
It's how much money you're leaving on the table by not starting.
Learn How To Build Monthly Income →