Receive and read a json with list inside, python

Asked

Viewed 53 times

0

Good afternoon, I’m using the reqparse library, but I don’t know if it works

I’m getting a json like this:

{
    "boletoPago": [
    {
        "numero_boleto" : 23564754,
        "valor_pago" : 350.00,
        "data_pagamento" : "2020-08-25"
    },
    {
        "numero_boleto" : 28965700,
        "valor_pago" : 180.00,
        "data_pagamento" : "2020-08-25"
    }
  ]
}

and I need to read every piece of these

using a code like this he only catches the first guy on the list

argumentos = reqparse.RequestParser()
argumentos.add_argument("boletoPago", type = str, required =True)
        args = argumentos.parse_args()
        for v in args:
            print(args[v])
  • https://answall.com/questions/206294/pega-dados-na-structura-json-com-python I think this should help you

  • does not work, I need to read the list inside the json and the keys inside the lists

1 answer

0

See if it helps you:

import json

with open('arquivo.json') as f:
    data = json.load(f)

#Acessando as listas
data["boletoPago"]
  • Puts Juan, it doesn’t help me much, not if it’s reqparse problem, but apparently it’s not getting the whole list, only her first position, IE, I can’t read the list

  • Try this to see if it’s right on add_argument use type=list and location='json'

Browser other questions tagged

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