knottty
knottty

Reputation: 21

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

code:

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

Upvotes: 1

Views: 604

Answers (1)

Tamil Selvan
Tamil Selvan

Reputation: 1749

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

Upvotes: 1

Related Questions