Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

560
Visualizações
TypeError: the JSON object must be str, not 'dict'

Sorry guys, I couldn't find the satisfying answer to print part of json response. Can someone help me here please:

import json
import requests
import pprint 

response = requests.get('<api endpoing>')
json_data = response.json()
print(json.dumps(json_data, indent=4, sort_keys=True))

Json response would be

{
    "Value1": "SomeValue",
    "data": {
        "subval1": false,
        "subval2": "0a4",
        "subval3": "",
        "subval4": "Click h!",
        "subval5": "1002",
        "subval6": "932",
        "subval7": "i2",
        "subval8": 250,
        "subval9": 0,
        "subval10": 1,
        "subval11": 3,
        "subval12": 1,
        "subval13": "<!>",
        "subval14": "",
        "subval15": "Click !!",
        "subval16": "",
        "subval17": 300
    },
    "error": true,
    "message": "Success",
    "status": 200
}

Now, I would like to traverse and print only the "data": values. I will do the following

data = json.loads(json_data)
data_set = (data['data'])
print(data_set)

But the error Im getting: TypeError: the JSON object must be str, not 'dict'

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You don't need to json.loads(json_data) as it is already a python dict, you just need to output this dict directly. And outputing json string from a dict is json.dumps()'s job :

json.dumps(json_data["data"])
over 4 years ago · Santiago Trujillo Relatório

0

Actually json() method returns a json object,so you don't need to use json.loads

Or you can use

r=requests.get("")
print json.loads(r.content)

See more details from JSON Response Content.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda