Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

544
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!