Created
July 23, 2013 23:16
-
-
Save smerritt/6066977 to your computer and use it in GitHub Desktop.
shows differences in JSON decoding between simplejson and stdlib json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import json | |
import simplejson | |
data = {'hello': 'world', u'ok': u'✓', | |
'nested': {'array': [1, 2, 3, {'potato': 'potato', | |
'tomato': 'tomato'}], | |
"that's": 'Numberwäng!'}} | |
if json.dumps(data) == simplejson.dumps(data): | |
print "encoding: same" | |
else: | |
print "encoding: different" | |
enc = json.dumps(data) | |
if repr(json.loads(enc)) == repr(simplejson.loads(enc)): | |
print "decoding: same" | |
else: | |
print "decoding: different" | |
print "simplejson\n==========\n%r\n\njson\n====\n%r" % (simplejson.loads(enc), | |
json.loads(enc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment