Reputation: 45
I am trying to convert a BSON from MongoDB to JSON to using bson.json_util.dumps but this function returns a string rather than a list.
i.e. [{"id":"demo"},{"id":"demo_new"}] --> '[{"id":"demo"},{"id":"demo_new"}]'
Which is difficult to iterate though as it takes the individual element from the string rather than the list.
Is iterating --> '[','{','"',"i","d" and so on Want the iteration to be --> {"id":"demo"} , {"id":"demo_new"}
Any suggestion how to make the string back to a list?
Upvotes: 0
Views: 464
Reputation:
I experienced the same issue.
My solution was the following:
from bson import encode, decode
json = decode(encode(...))
The ... is where you put your query.
Upvotes: 1