I'm pulling a json object from a url:
import requests
r = requests.get('http://my.endpoint.com/Hardware.json')
Now I need to convert this from r.json() to a dict, so that I can insert it as a document to MongoDB (I think. I'm new to Mongo, soo).
When I try:
import json
d = json.loads(r.json())
It fails with:
TypeError: expected string or buffer
Ultimately, I just want an object type that I can pass into MongoClient().test.hosts.insert_one() as a new document, from pymongo.
r.json() can return a dict or a list so there's no need to convert it to JSON.
If it is a dict then insert_one() should work just fine but if it is a list then you need to use insert_many() method instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With