How to Read .Json files in Python - #LearningPython 17

Subscribers:
2,490
Published on ● Video Link: https://www.youtube.com/watch?v=j1xpEJQ5EzI



Category:
Guide
Duration: 8:51
16 views
2


Today I learned a bit more about Python, and how I can read .json files.
The use of json files is apparently extremely common, since it's very easy to a computer to read and it is very compact, meaning it's even easier to process, and because it's that used, almost all programming languages have an easy way of reading json files, and Python is no exception.
Basically I can read a json file just as I can a normal .txt file.:

import json

with open("file.json", "r") as arq_json:

in this code above I am opening a .json file with the intent of Reading it and save this information as arq_json, and then I can process it. A interesting thing to note is that I NEED to specify the 'import json' part or it will not recognize it, probably because json does work a bit different than other extensions, and it shows, since if you want to extract the info from the json file, you need to:

info = json.load(arq_json)

The 'weird' part here is the .load part, since until now we just used .read, .readline or .readlines, but here I do a .load, which apparently loads ALL the info inside, which shows me that .json aren't SUPPOSED to be super long or big.

The course in using (it's in Portuguese, but free): https://on.fiap.com.br/local/salavirtual/conteudo-digital.php

If you have any question or suggestion on other topics, feel free to comment down below or ask me in Facebook or Instagram!

Visit my Facebook Page in: http://fb.com/teteusbionicoficial
Visit my Instagram: https://www.instagram.com/teteusbionic/
Visit my Website: http://www.teteusbionic.com.br







Tags:
Programação de Jogos
Curso de Programação de Jogos
Palestra Programação de Jogos
Oficina Programação de Jogos
Scratch
Fazer Jogo
Criar um Jogo
Como fazer um jogo
Fazer um jogo sozinho