0

I am trying to turn my dictionary (which is a response from an API call) into a JSON file of some sort to be able to send/read the data.

I've googled the last day, and everything I've had seems to not work, I just keep getting a variation of errors.

This is the most recent:

for x in range(0, loops):
response = requests.get(url=url, headers=headers, params=parameters)
jira_data = json.loads(response.content)
with open('jira_response_data.txt', 'w+') as fd:
    fd.write(json.loads(jira_data))
    fd.close()

The internet says that json.loads should turn my dict into JSON. But when I run this, I get:

TypeError(f'the JSON object must be str, bytes or bytearray, 
TypeError: the JSON object must be str, bytes or bytearray, not dict

So based on that, it looks like it's still taking jira_data as a dictionary.

Note: I'm not a dev, and I'm new to python and programming, so go easy on me.

1 Answers1

1

You need dump to file. Not load from it. Also you can use json.dump than understand files (instead of json.dumps).

with open('jira_response_data.txt', 'w+') as fd:
    json.dump(jira_data, fd)
Danyla Hulchuk
  • 411
  • 3
  • 6