[Python] add JSON objects to specific index - Python

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I started with JSON and Python 3.x... So there are still some problems. This is now my first important problem I have.

    I'm looking for a function which can insert (for example) this:

    {
    'Current': '3A',
    'Voltage': '11V'
    }


    In to here:

    {
    'Measure': [
    {'Current': '2A', 'Voltage': '11V'}
    ]
    }


    ...so that my result is:

    {
    'Measure': [
    {'Current': '2A', 'Voltage': '11V'},
    {'Current': '3A', 'Voltage': '11V'}
    ]
    }


    I only found functions in JavaScript to solve my problem, in Python not. Till now, I saw only a hierarchical creation method for JSON and nothing like a class and instance build up.

    I hope, there are opportunities to do it. Any ideas?

    Continue reading...

Compartilhe esta Página