👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
JSON stands for JavaScript Object Notation. It is a JavaScript object that organizes data into key / value pairs. Storing data in this way makes these objects lightweight and language independent. This means that JSON can be read by most programming languages.
JSON is commonly used to retrieve data from a client side server because it is lightweight and easily readable by humans and machines. In a world of API consumption, JSON is flexible enough to pull only the data you want from the server to the user.
Using JSON
Using JSON is a convenient way to store data passed from the server to the front-end of an application. Most programming languages ​​have methods for immediately converting data to JSON. In a JavaScript fetch request, the data response sent by the server is converted to JSON by calling the json ()
method on the request. Learn more about fetch queries here.
Why should we always convert a response to JSON ? One answer is wordy and difficult for us humans to decipher. By converting the response to JSON, we organize the data into human readable key / value pairs. This makes the data more accessible through the code that we write to do something with the response data.
JSON Examples
First, let’s take a look at what a response that was converted to JSON might look like. We send a fetch request to an API that tells us how many astronauts are currently in space in the example below.
For our purposes, we’ll save the response we converted to JSON in our console.
We can see that inside this object there is the slave ch of "message,‚" "number‚" and "people.‚" The message key indicates " success .‚" This is a nice message to us. let us know the status of our request.