How to change the value of an object in python . json

Asked

Viewed 946 times

2

how do I change the value of an object in python . json (without rewriting it all)? Ex:

{
    "Nome": "Henrique Antônio de Oliveira"
    "Cidade": "São Paulo"
    "Estado": "São Paulo"
    "Idade": "23"
    "Número do Pedido:": "457835"
}

How would I change his age without rewriting the whole . json? Since then I thank you!

1 answer

2


Changing the value by key. Example:

import json

j = json.loads('{"Nome": "Fulano", "Idade": "23"}')
j['Idade'] = '12'

IDEONE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.