Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,490 --> 00:00:09,240
A JSON format stands for Javascript Object Notation. And you might have noticed this as well.
2
00:00:09,240 --> 00:00:17,130
The data that we get back looks remarkably like how we create Javascript objects, where we open up a
3
00:00:17,130 --> 00:00:18,510
set of curly braces,
4
00:00:18,510 --> 00:00:27,120
we have our key, then our colon, then our value, and each of these key value pairs are then separated by
5
00:00:27,120 --> 00:00:32,600
commas, and we can embed objects inside other objects.
6
00:00:32,610 --> 00:00:35,370
Now there are a couple of differences though,
7
00:00:35,640 --> 00:00:41,970
say, for example, when we create an actual object in Javascript we always have a var or a let keyword in
8
00:00:41,970 --> 00:00:42,870
front,
9
00:00:42,900 --> 00:00:49,620
we have the name of the object without any quotation marks around it, because it's not a string,
10
00:00:49,920 --> 00:00:54,390
and inside our object, the keys are never strings, right?
11
00:00:54,390 --> 00:01:02,700
They're simply written as they are. Now the reason why we use a JSON to pass data around on the Internet
12
00:01:03,140 --> 00:01:10,560
is because it's in a format that can be readable by a human, but it can also be easily collapsed down
13
00:01:10,590 --> 00:01:13,890
to take up as little space as possible.
14
00:01:13,890 --> 00:01:21,840
So it's almost like if your Javascript object is a full sized wardrobe, but while you're transporting
15
00:01:21,840 --> 00:01:21,980
it,
16
00:01:21,990 --> 00:01:27,030
if you bought it from the store and you're taking it home, you probably don't want to move it as an entire
17
00:01:27,030 --> 00:01:28,530
wardrobe, right?
18
00:01:28,620 --> 00:01:37,050
Just like the flat pack furniture at IKEA, you can collapse all of that data down into a single string.
19
00:01:37,350 --> 00:01:42,470
And as long as we maintain where all the curly braces and the colons and the commas are,
20
00:01:42,900 --> 00:01:51,660
then at a later stage, once we received that JSON as a string, we can build it back up into the original
21
00:01:51,750 --> 00:01:52,900
object.
22
00:01:52,980 --> 00:01:58,110
Now JSON is not the only format that we can receive data from
23
00:01:58,110 --> 00:02:06,120
APIs. Very frequently you'll find that various APIs, like OpenWeatherMap, will provide multiple formats
24
00:02:06,240 --> 00:02:08,600
for you to be able to get data from them.
25
00:02:08,639 --> 00:02:15,460
So in addition to JSON, you'll often find a format called XML, which is extensible markup language,
26
00:02:15,510 --> 00:02:20,250
or it could also come back as simple HTML, hypertext markup language.
27
00:02:20,820 --> 00:02:27,720
But JSON is currently the most favoured format, because it's much lighter weight than the other two,
28
00:02:27,930 --> 00:02:34,400
and also because it's very easy to turn back into a Javascript object.
29
00:02:34,400 --> 00:02:41,820
Now if you want to prettify the output that we get in our browser, similar to how Postman does it, turn
30
00:02:41,850 --> 00:02:44,660
the raw output into a pretty version,
31
00:02:44,880 --> 00:02:49,190
you can go ahead and download a Chrome browser add on called JSON Viewer
32
00:02:49,200 --> 00:02:50,160
Awesome.
33
00:02:50,250 --> 00:02:57,990
It's, again, free to download, and you can simply add it to Chrome as an extension. Once it's been added,
34
00:02:58,110 --> 00:02:59,190
you'll see it up here.
35
00:02:59,610 --> 00:03:06,570
And now if I go back to that previous API request and I refresh it, you'll see it now gets formatted
36
00:03:06,900 --> 00:03:16,710
by JSON Viewer Awesome into a tree structure, or a chart structure, or the original JSON input.
37
00:03:16,770 --> 00:03:23,220
Another really useful thing about JSON Viewer Awesome is, when we click on the individual pieces of
38
00:03:23,220 --> 00:03:24,180
data that we want,
39
00:03:24,180 --> 00:03:30,140
say this id, or this icon, and we hover over this green button,
40
00:03:30,330 --> 00:03:38,340
we can actually either copy the value, or copy the path that it takes to get to this particular value.
41
00:03:38,340 --> 00:03:40,970
Notice how we can collapse some of these trees.
42
00:03:41,070 --> 00:03:45,220
So this icon is nested inside an array,
43
00:03:45,330 --> 00:03:48,320
inside this weather piece of data,
44
00:03:48,570 --> 00:03:52,480
and then that is inside the original 13 item
45
00:03:52,860 --> 00:03:54,390
JSON object.
46
00:03:54,390 --> 00:04:01,690
So if I go ahead and just paste what I copied just now, you can see that to get to that icon, we first tap
47
00:04:01,710 --> 00:04:10,950
into the JSON object, and then get hold of the weather object, and then get the first item, the 0 item
48
00:04:11,370 --> 00:04:12,720
inside the array,
49
00:04:12,720 --> 00:04:17,490
and finally we tap into the value of the key icon.
50
00:04:18,060 --> 00:04:24,570
So once we've turned our JSON into a JSON object, this is how we would get hold of this piece of data
51
00:04:24,680 --> 00:04:26,600
to use in our web site.
52
00:04:26,610 --> 00:04:29,390
This is what we're going to be doing in the next lesson.
53
00:04:29,490 --> 00:04:34,770
We're going to be putting into practice everything that we've learned about APIs and the JSON data
54
00:04:34,800 --> 00:04:43,110
format, in order to use the OpenWeatherMap API to create our own web site that shows the weather for
55
00:04:43,110 --> 00:04:49,660
certain cities, and also allow the user to search for the weather in certain cities.
56
00:04:49,680 --> 00:04:53,790
This is what we'll be doing in the next lesson, so hopefully I'll see you there.
5986
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.