Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem returning data with json.loads, I can't solve it

I’m trying to return a specific value from my json with json.loads and I’m not getting it. I want it to return the value of ‘linkBoleto’:

This is the structure of my json file

{  
   "retorno":{  
      "contasreceber":[  
         {  
            "contareceber":{  
               "id":"13123121",
               "situacao": "aberto", 
               "dataEmissao":"2017-03-09",
               "vencimentoOriginal":"2017-03-09",
               "vencimento":"2017-03-09",
               "competencia":"2017-03-01",
               "nroDocumento":"0123456",
               "valor":15.00,
               "saldo":0.00,
               "historico":"Referente ao pedido de venda nº 423",
               "categoria":"Vendas",
               "idFormaPagamento": "123",
               "portador":"CEF",
               "nroNoBanco":"00100358-56",
               "vendedor":"Vendedor exemplo",
               "pagamento": {
                    "totalPago": 15.00,
                    "totalJuro": 0,
                    "totalDesconto": 0,
                    "totalAcrescimo": 0,
                    "totalTarifa": 0,
                    "data": "2017-03-09"
               },
               "ocorrencia":"Unica",
               "linkBoleto":"https://www.bling.com.br/doc.view.php?132",
               "cliente":{  
                  "nome":"Organisys Software",
                  "cpf_cnpj":"00.000.000/0000-1",
                  "tipoPessoa":"J",
                  "ie_rg":"0000000000",
                  "endereco":"Rua Barão do Rio Branco",
                  "numero":"000",
                  "complemento":"Sala 000",
                  "cidade":"Bento Gonçalves",
                  "bairro":"Centro",
                  "cep":"00.000-000",
                  "uf":"RS",
                  "email":"teste@organisys.com.br"
               }
            }
         }
      ]
   }
}

I tried this, but I couldn’t…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import requests
import json

cnpj_consulta = '00.000.000/0000-1'
api_key = 'my-api-key'
url = 'https://bling.com.br/Api/v2/contasreceber/json/'
f_key ='&apikey='
f_cnpj = '&filters=cnpj'
op = '['
cl = ']'

r = requests.get(f'{url}{f_key}{api_key}{f_cnpj}{op}{cnpj_consulta}{cl}')

y = json.loads (r.content)

print (y ['linkBoleto'])

I can return data from the api normally but when I try to apply json.loads to limit the return I can’t…

>Solution :

You can’t access "linkBoleto" directly, you need to follow the structure of JSON:

print(y["retorno"]["contasreceber"][0]["contareceber"]["linkBoleto"])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading