JavaScript JSON Parse Tutorial - What is it and how to use it?

preview_player
Показать описание

The JavaScript JSON parse function is something you’ll become quite familiar with and use frequently within your code. This is especially true if you’re writing code outside of a framework like React / Angular / Vue.

So the first question you probably have is ‘What does the JavaScript JSON parse function do?’ Well, the answer is quite simple once you understand the difference between JSON and JavaScript objects.

I’ll clear that up for you first in the tutorial where we see how JSON data is really just a string representation of an object which means you can’t access it’s properties directly. Only real JavaScript objects can be accessed in this way.

Knowing the difference between JSON and JavaScript objects, it’s easy to work out that the JSON parse function simply takes a JSON string and converts it to a real JavaScript object so that we can access it’s properties.

In the rest of the tutorial we’ll look at working with JSON data from remote calls (like JSON sent back from an API) using JavaScript JSON parse from url, and how the data needs to be parsed when returned in a string-like format.

We’ll also go through another example using the Fetch API to retrieve data and you’ll see how, if you use this technique to retrieve external data, you don’t actually need the JavaScript JSON parse function.

Finally, in our JavaScript JSON parse tutorial, you’ll learn about the one common mistake that a lot of new developers make when working with JSON data, particularly when not handling a JavaScript JSON parse error. It’s necessary a lot of the time to to check the data you are trying to parse is valid JSON as passing in an invalid string will cause an error. With the two remote call examples, i’ll show you how to handle these types of errors and make sure your JavaScript code continues gracefully. Channel Handle @codebubb
Рекомендации по теме
Комментарии
Автор

You literally helped me in a WebSocket project I'm building, parsing the WebSocket JSON data...thank you.

jimmyopot
Автор

I just had to pause the video to write this comment. This video is god sent. Some of the questions that were buggin me about json are finally answered here. A million thanks for this!!

katdareshruti
Автор

Jesus, I been trying to find the answer to the most basic of questions and u answered in the first 3 mins. I just want to say thanks!

chrislauer
Автор

Thank you very much the data.json() answers one of my question when you are using fetch.

cebuanoninoy
Автор

What is the difference between json.parse() and jackson library's object mapper class?

katdareshruti
Автор

Hi Guys.
How do we save HTML form data to JSON?

rishengopaldass
Автор

Hello when I use json.parse () while I don't get errors i also don't get any output in the console
Is that because I didn't include link to jQuery?
If so which jQuery link do we need to include?
Thanks alot Lisa

pjmclenon
Автор

Thank for video. Bu i have a question. If you not know name of attributes (like >> 'name' or 'languages') how do you parse json ?

ITUCs
Автор

Zio pera, ho visto 100 video di voi che vi create i dizionari e nessuno che cazzo carica un fottuto file con javascript.

idontcare
Автор

Asking for likes and subscribes before the video has even started is extremely cringe.
Probably a good idea to save that until the end when we can actually ascertain if the like and sub are worth it.
Unfortunately, I chose to not bother watching the video b/c of it.

The_Pariah
Автор

10 minutes to explain what, a single function? Waste of time, but, you hit all your keywords in the description. Hey, want to get hired as a senior react or angular developer? Just learn JSON.parse and you'll be well on your way.

Vball