Skip to content

Instantly share code, notes, and snippets.

@syoyo
Created October 15, 2009 03:41
Show Gist options
  • Save syoyo/210648 to your computer and use it in GitHub Desktop.
Save syoyo/210648 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json # Use JSON library provided by python 2.6
from pymongo.bson import BSON
mycamera = {"name" : "muda"}
mygeom = {"p" : [1.0, 0.0, 1.0, 2.0, 0.0, 1.0, 3.0, 2.0, 1.0]}
scene = {"global" : {"camera" : mycamera, "geom" : [mygeom]}}
bson_string = BSON.from_dict(scene)
json_string = json.dumps(bson_string.to_dict())
print "As binary form = ", repr(bson_string)
print ""
print "As python dict = ", bson_string.to_dict()
print ""
print "As JSON = ", json_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment