Skip to content

Instantly share code, notes, and snippets.

@ask
Created April 20, 2009 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ask/98452 to your computer and use it in GitHub Desktop.
Save ask/98452 to your computer and use it in GitHub Desktop.
data = {
"foo": "The quick brown fæx jomps øver da læzy dåg",
}
x = encode(data)
print("ENCODED: %s" % x)
e = decode(x)
print("DECODED: %s" % e)
import simplejson
import cjson
test_json(simplejson.dumps, simplejson.loads)
test_json(cjson.encode, cjson.decode)
"""
Output:
TESTING JSON simplejson
ENCODED: {"foo": "The quick brown f\u00e6x jomps \u00f8ver da l\u00e6zy d\u00e5g"}
DECODED: {'foo': u'The quick brown f\xe6x jomps \xf8ver da l\xe6zy d\xe5g'}
TESTING JSON cjson
ENCODED: {"foo": "The quick brown f\u00c3\u00a6x jomps \u00c3\u00b8ver da l\u00c3\u00a6zy d\u00c3\u00a5g"}
DECODED: {'foo': u'The quick brown f\xc3\xa6x jomps \xc3\xb8ver da l\xc3\xa6zy d\xc3\xa5g'}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment