1
00:00:00,860 --> 00:00:06,569
So I believe it was quite easy to
realize that the best way to load this

2
00:00:06,569 --> 00:00:11,849
data in Python is a Python dictionary. So
this looks just like a Python dictionary

3
00:00:11,849 --> 00:00:16,890
and once we load it in in the Python
dictionary then it becomes very easy to

4
00:00:16,890 --> 00:00:24,029
access a value for a key. So how do we
load this into a Python dictionary? Well

5
00:00:24,029 --> 00:00:30,980
I let me open a command shell here.
For now I'm just going to demonstrate

6
00:00:30,980 --> 00:00:36,059
something quick in an interactive Python
shell, but first you may need to close

7
00:00:36,059 --> 00:00:42,090
this JSON file because this is slowing
down Atom. Don't save the changes. I

8
00:00:42,090 --> 00:00:47,760
didn't do any change anyway. So python 3.
That will open my Python 3.6.1,

9
00:00:47,760 --> 00:00:52,379
but anyway even if you have
Python 2 this program will work the

10
00:00:52,379 --> 00:00:58,140
same. So how do you load JSON into a
Python dictionary? Well, for that we need to

11
00:00:58,140 --> 00:01:02,850
use the JSON standard library. With a
standard library it means that you don't

12
00:01:02,850 --> 00:01:09,170
need to install JSON. You just need to go
ahead and import it. Once you do that

13
00:01:09,170 --> 00:01:17,580
there is a nice JSON.load method
there and this load method, this

14
00:01:17,580 --> 00:01:24,380
expects, actually I can show it like this.
Help JSON dot load.

15
00:01:25,890 --> 00:01:35,820
So this gets this argument here which is
a file like object that contains a JSON

16
00:01:35,820 --> 00:01:41,070
document, so we're talking about the file
object in Python and we need to create

17
00:01:41,070 --> 00:01:49,560
that file. The way to do that is simple.
So JSON again dot load. The way

18
00:01:49,560 --> 00:01:54,590
we create a file object is by using
the open method. You know that already.

19
00:01:54,590 --> 00:02:05,100
Then you pass the path to the file.
Now since my terminal here is pointing

20
00:02:05,100 --> 00:02:10,440
to this folder I just need to pass the
file name I don't need to pass any full

21
00:02:10,440 --> 00:02:15,600
path in there, so like that you can either
pass the R method which stands

22
00:02:15,600 --> 00:02:20,820
for read mode or you can just leave
it like that and the read mode is by

23
00:02:20,820 --> 00:02:26,400
default. Make sure to close brackets two
times. So we have two opening brackets

24
00:02:26,400 --> 00:02:36,170
here. Two closing brackets in here and
that's all. Now what is data? Data is a

25
00:02:36,290 --> 00:02:45,420
dictionary, so it's a Python dictionary
and you can print it out. Yeah, it's quite

26
00:02:45,420 --> 00:02:47,989
a lot of data. So that took a while,
but normally you do not have to

27
00:02:59,110 --> 00:03:08,200
print out the entire dictionary. What
you could check is to access a word and

28
00:03:08,200 --> 00:03:14,290
a key from the dictionary. Let's say the
key rain. You need to use brackets, sorry

29
00:03:14,290 --> 00:03:23,530
quotes for the key. This is what you get.
So yet the value for the word rain, for

30
00:03:23,530 --> 00:03:27,550
the key rain. So now that you know how
this works

31
00:03:27,550 --> 00:03:35,170
more or less, try to come up with a
function that gets as input a key and

32
00:03:35,170 --> 00:03:40,600
then returns the value for that
particular key and also try to

33
00:03:40,600 --> 00:03:47,260
incorporate the loading of the JSON file
and also print out the output. So if you

34
00:03:47,260 --> 00:03:52,000
have issues with that, in the next video
I'll show you how we do that. See you there.

