[Python] How to dynamically build a JSON object?

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to Python and I am playing with JSON data. I would like to dynamically build a JSON object by adding some key-value to an existing JSON object.

    I tried the following but I get TypeError: 'str' object does not support item assignment:

    import json

    json_data = json.dumps({})
    json_data["key"] = "value"

    print 'JSON: ', json_data

    Continue reading...

Compartilhe esta Página