Skip to content

Instantly share code, notes, and snippets.

@smerritt
Created July 23, 2013 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smerritt/6066977 to your computer and use it in GitHub Desktop.
Save smerritt/6066977 to your computer and use it in GitHub Desktop.
shows differences in JSON decoding between simplejson and stdlib json
#!/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