diff --git a/aula117.json b/aula117.json new file mode 100644 index 0000000..4534369 --- /dev/null +++ b/aula117.json @@ -0,0 +1,24 @@ +{ + "nome": "Luiz Otávio 2", + "sobrenome": "Miranda", + "enderecos": [ + { + "rua": "R1", + "numero": 32 + }, + { + "rua": "R2", + "numero": 55 + } + ], + "altura": 1.8, + "numeros_preferidos": [ + 2, + 4, + 6, + 8, + 10 + ], + "dev": true, + "nada": null +} \ No newline at end of file diff --git a/aula117.py b/aula117.py new file mode 100644 index 0000000..e6a87a2 --- /dev/null +++ b/aula117.py @@ -0,0 +1,28 @@ +import json + +pessoa = { + 'nome': 'Luiz Otávio 2', + 'sobrenome': 'Miranda', + 'enderecos': [ + {'rua': 'R1', 'numero': 32}, + {'rua': 'R2', 'numero': 55}, + ], + 'altura': 1.8, + 'numeros_preferidos': (2, 4, 6, 8, 10), + 'dev': True, + 'nada': None, +} + +with open('aula117.json', 'w', encoding='utf8') as arquivo: + json.dump( + pessoa, + arquivo, + ensure_ascii=False, + indent=2, + ) + +with open('aula117.json', 'r', encoding='utf8') as arquivo: + pessoa = json.load(arquivo) + # print(pessoa) + # print(type(pessoa)) + print(pessoa['nome'])