Sankit Acharya
Sankit Acharya

Reputation: 45

bson.josn_util returns a string not a list

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

Answers (1)

user12524590
user12524590

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

Related Questions