Asked • 06/08/19

How do I write JSON data to a file?

I have JSON data stored in the variable `data`.I want to write this to a text file for testing so I don't have to grab the data from the server each time.Currently, I am trying this: obj = open('data.txt', 'wb') obj.write(data) obj.closeAnd am receiving the error: `TypeError: must be string or buffer, not dict`How to fix this?

1 Expert Answer

By:

Matthew P. answered • 10/09/19

Tutor
4.9 (54)

Software Engineer with BSE degree in Computer Science

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.