Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to convert BSON to JSON on python?

im catching program packets and i got this bson: GwAAAAJJRAADAAAAU1QAElQAseX+LO++2QgAEG1jAAEAAAAA

Also i found a site to convert it to json, but its on java script, how to make similar using python?

site: http://mcraiha.github.io/tools/BSONhexToJSON/bsonbase64tojson.html

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

code:

import base64
import bsonjs
b64String = base64.b64encode(data)
packet = b64String[16:]
print(packet)

>Solution :

This is can solve your need

import bsonjs
import base64
yourString = "GwAAAAJJRAADAAAAU1QAElQAseX+LO++2QgAEG1jAAEAAAAA"
outJSON = bsonjs.dumps(base64.b64decode(yourString))
print(outJSON)

output Dict:

{ "ID" : "ST", "T" : 637750756710999473 }

Let me know if you have any issues please

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading