From the course: JavaScript: Ajax and Fetch
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Work with JSON data - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Work with JSON data
- Once you have the response from your AJAX request, you have to dig into it and find the specific data you need. JavaScript Object Notation, or JSON, is by far the most common format used to exchange data on the modern web. JSON data is transmitted as a string, so the first thing you need to do is parse it into the data format it encodes. Although the word object is in the name, JSON data could parse out either as an object or as an array, which is technically just another type of object in JavaScript. To parse JSON, you use the parse method of the JSON object which is built into JavaScript. Now that we have a string of data back from our web service, to go any further in our code we'll need to parse that. So, in my updateUISuccess function I want to create a new variable called parsedData and I'm going to set that equal to JSON.parse and I'm going to grab the value of data, which is that JSON string that came in from my API call. So JSON, all caps, is the name of the object that we…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
What is the DOM?3m 19s
-
(Locked)
Select elements with vanilla JavaScript3m 43s
-
(Locked)
Request data in response to an event4m 14s
-
(Locked)
Add an event listener2m 12s
-
(Locked)
Work with JSON data6m 52s
-
(Locked)
Modify form values with vanilla JavaScript4m 58s
-
(Locked)
Modify element content with vanilla JavaScript5m 49s
-
(Locked)
Challenge: Modify the DOM58s
-
(Locked)
Solution: Modify the DOM7m 55s
-
-
-
-
-