Asynchronous JavaScript Tutorial #5 - Using JSON Data
Skills:
JavaScript Fundamentals80%
Key Takeaways
Demonstrates using JSON data in asynchronous JavaScript programming
Full Transcript
so hopefully by now you understand the basics of how to make http requests now i'd like to talk about json which is a data format that most apis return to us when we make a request it's the kind of data we're getting back here this is all json data it looks like an array with loads of javascript objects inside it but it's not it's just a string the string is formatted in a way that looks like javascript objects with curly braces and key value pairs but it is still just a string and that's all json essentially is strings which look like javascript objects and it has to be a string because when a browser exchanges data with a server it has to be done in text format that is the format of data transfer and that is why we use this format json so what we need to do is figure out a way of taking this json string we get back and turning it into a real javascript object so that we can access all of the different to-do's easily because as it is it would be really hard to count how many different to-do's are in this list and also to access the properties from each to do that kind of stuff is much easier if we have the to-do's nicely packaged into objects in an array now fortunately there is an object built into the javascript language which we can use to do this so let's go and try it out so when we get the data back over here what we're going to do instead of passing the response text is first of all we're going to take all that json and turn it into a javascript array of objects so how do we get that well let's store this first of all in a const called data and i'm going to set this equal to json all in capitals so that's how we spell json and it stands for javascript object notation because they look like objects so we use that object and then we use a method on this called pass so this method takes in adjacent string and then what it does is convert that json string into javascript objects that we can then use easily in the code so what i'm going to do is take this response text which is the json string and i'm going to pass it in here and now over here we're going to get an array of javascript objects because this takes the response text the json string and it passes it into javascript objects so now i'm going to pass this through down here as an argument instead of the response text directly so now when we log it down here it should actually be javascript objects an array of them so let's save it and give this a whirl and now we can see we have this huge array it's no longer json it's an array with 200 elements inside and inside are loads of different objects and we can see each object has all these different properties which we could then if we wanted to cycle through and access now we're not going to do that yet but we will explore how we do that kind of stuff later on so that's how we take a json string that we receive back from some kind of server when we make a request to an endpoint but we can also create our own json as well so let me show you how we can do that so over in our text editor i'm going to create a new file and i'm going to call this to do's dot json so when we make a json file it has a json extension now in here remember the json looks like an array of objects now we don't have to put it in string syntax like this it's a json file so it automatically knows it's going to be a json string all we have to do is write it out so we have our array first of all and inside are going to be different things that look like objects now the difference between when we're writing json objects and regular javascript objects is that all of our keys have to go in double quotes and when we use a string as a value they have to go in double quotes as well we can't use single quotes so whereas in a javascript object we could do something like this the key would be text and the value would be something like play mario kart and then we could have a key which is author and that would be sean this is not valid jason and notice we've got all these red squiggles everywhere that's because this is not valid and when we write jason everything has to be in double quotes so this has to be in a double quote and when we use a string as a value that also has to be in a double quote so let's replace these right now and do the same for author and the value of author now if we were to use numbers as values for example if i did a points key and put that equal to 50 this 50 is fine not going in double quotes we don't have to do that only when we're using strings as values likewise if it was a boolean like true or false we don't have to put those in double quotes either so let's just delete those for now and keep it simple with two different properties now let's just add another couple of different json objects these are comma separated so i'm going to do a comma then i'm just going to duplicate this and duplicate it again the last one doesn't have a comma though then the text the second time around is going to be by some bread and the author is going to be mario and then the third text is gonna be do the plumbing and the author is gonna be luigi okay so now we have this valid json so if i save this now and come over to the sandbox instead of now reaching out and trying to get this what i could do if i wanted to is just try and grab this so i'm going to do the relative url to get this which is to do's dot json because we're in the same directory as the sandbox so now we're gonna go out and we're gonna try and reach this so if we save it now and refresh now we can see we get that data back as an array and javascript objects because we pass that json over here into that so whenever we make a request to some kind of endpoint and it's serving us back some json data essentially what it's doing is on their server it's getting some json from somewhere like we've got json from here and it's just sending that json back to us to the browser then we can pass it into some kind of real data that we can use inside the javascript and that is the crux of json it's a way of transferring data between server and client
Original Description
Hey gang, in this async javascript tutorial we'll make a request to get JSON data.
Get the full Modern JavaScript tutorial on Udemy here (discount auto-applied):
https://www.thenetninja.co.uk/udemy/modern-javascript
🐱👤🐱👤 JOIN THE GANG -
https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg/join
----------------------------------------
🐱💻 🐱💻 My Udemy Courses:
+ Modern JavaScript - https://www.thenetninja.co.uk/udemy/modern-javascript
+ Vue JS & Firebase - http://www.thenetninja.co.uk/udemy/vue-and-firebase
+ D3.js & Firebase - https://www.thenetninja.co.uk/udemy/d3-and-firebase
🐱💻 🐱💻 Helpful Links:
+ Get VS Code - https://code.visualstudio.com/
🐱💻 🐱💻 Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: JavaScript Fundamentals
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI