Skip to content

Instantly share code, notes, and snippets.

@1900
Created September 5, 2012 08:46
Show Gist options
  • Save 1900/3633505 to your computer and use it in GitHub Desktop.
Save 1900/3633505 to your computer and use it in GitHub Desktop.
simplejson Encoding demo
>>> import simplejson as json
>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
>>> print json.dumps("\"foo\bar")
"\"foo\bar"
>>> print json.dumps(u'\u1234')
"\u1234"
>>> print json.dumps('\\')
"\\"
>>> print json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
{"a": 0, "b": 0, "c": 0}
>>> from StringIO import StringIO
>>> io = StringIO()
>>> json.dump(['streaming API'], io)
>>> io.getvalue()
'["streaming API"]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment