8 Tweets Jan 31, 2023
What is JSON, and how to use it in Javascript?
Thread ๐Ÿงต๐Ÿ‘‡
JSON stands for JavaScript Object Notation.
It is a text-based, open standard data format used for storing and transmitting data.
We can also describe it as a human-readable text format that uses JavaScript object notation.
Below you can see a sample JSON object.
It's an object with property value pairs.
As you can see, the JSON is similar to classic Javascript objects, which makes it easy to manipulate in Javascript code.
Javascript has built in-functions for converting JSON strings to JS objects and vice-versa.
You can use the parse method to convert JSON objects to Javascript objects.
You can use the stringify method to convert a Javascript object into a JSON string.
Tip ๐Ÿ’ก
Sometimes you may find it useful to use the prettified output (e.g. output to console).
For this stringify uses the third parameter that specifies the spacing level.
APIs widely use JSON to send a payload to a server and receive the resource data.
If we compare it with XML it's much easier to read and it uses less bandwidth.
Below you can see a sample fetch request for posting JSON data to the API.
Thanks for reading!
Follow us @Rapid_API for more exclusive content. ๐Ÿ™๐Ÿ’™

Loading suggestions...