[Python] How to extract nested json using json_normalize?

Discussão em 'Python' iniciado por Stack, Março 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have a nested json, but I can't understand how to work with them.

    {
    "return":{
    "status_processing":"3",
    "status":"OK",
    "order":{
    "id":"xxxxx",
    "number":"xxxx",
    "date_order":"dd/mm/yyyy",
    "itens":[
    {
    "item":{
    "id_product":"284845",
    "code":"",
    "description":"",
    "unit":"Un",
    "quantity":"1.00",
    "unit value":"41.90"
    },
    "item2":{
    "id_product":"284846",
    "code":"",
    "description":"",
    "unit":"Un",
    "quantity":"1.00",
    "unit value":"41.90"
    }
    }
    ]
    }
    }
    }


    I searched on stackoverflow questions, and try some resolutions that people passed, but don't work for me.

    Here an sample that I used to accessing the data from json:

    df = pd.json_normalize(order_list, record_path= ["return", "order", "itens"],
    meta=[["return", "order", "id"], ["return", "order", "date_order"],["return", "order", "number"]])


    but don't work, they duplicating the data when I send to dataframe.

    Anyone can help me ?

    EDIT

    Here an example that I used: Convert nested JSON to pandas DataFrame

    Continue reading...

Compartilhe esta Página