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

Work with JSON data - JavaScript Tutorial

From the course: JavaScript: Ajax and Fetch

Start my 1-month free trial

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…

Contents