Untitled

mail@pastecode.io avatar
unknown
python
a month ago
532 B
5
Indexable
Never
import json

# Corrected JSON string
desafio_json = '''{
    "name": "john smith",
    "age": 30,
    "city": "New York",
    "isStudent": True,
    "gpa": 3.5
}'''
# Salvando arquivo Json
with open('desafio.json', 'w', encoding='utf-8') as arquivo_json:
    json.dump(desafio_json, arquivo_json)

# Lendo arquivo Json
with open('desafio.json',encoding='utf-8') as arquivo_json:
    string_desafio_json = json.load(arquivo_json)
    dicionario_desafio_json = json.loads(string_desafio_json)
    print(dicionario_desafio_json['age'])
Leave a Comment