[issue6566] json.dumps converts None to null (not null)
Kirubakaran Athmanathan pyb...@kirubakaran.com added the comment: Here is the patch that fixes for 2.7 -- keywords: +patch nosy: +kirubakaran Added file: http://bugs.python.org/file24899/6566.2.7.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Kirubakaran Athmanathan pyb...@kirubakaran.com added the comment: Here is the patch that fixes for 3.3 -- Added file: http://bugs.python.org/file24900/6566.3.3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 7c818b4cd98a by Senthil Kumaran in branch '2.7': explain json.dumps for non-string keys in dicts. closes issue6566. Patch contributed Kirubakaran Athmanathan http://hg.python.org/cpython/rev/7c818b4cd98a New changeset 613919591a05 by Senthil Kumaran in branch '3.2': 3.2 explain json.dumps for non-string keys in dicts. closes issue6566. Patch contributed Kirubakaran Athmanathan http://hg.python.org/cpython/rev/613919591a05 New changeset 0554183066b5 by Senthil Kumaran in branch 'default': merge from 3.2 - issue6566 http://hg.python.org/cpython/rev/0554183066b5 -- nosy: +python-dev resolution: - fixed stage: - committed/rejected status: - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Éric Araujo mer...@netwok.org added the comment: Shouldn’t the 2.7 docs talk about str and unicode, or maybe basestring, instead of just str? -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Kirubakaran Athmanathan pyb...@kirubakaran.com added the comment: The note added Keys in key/value pairs of JSON are always of the type str. When a dictionary is converted into JSON, all the keys of the dictionary are coerced to strings. is true for unicode keys too. '{foo: bar}' -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Kirubakaran Athmanathan pyb...@kirubakaran.com added the comment: json.dumps({u'foo':'bar'}) '{foo: bar}' -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Merlijn van Deen valhall...@gmail.com added the comment: JSON does not have the distinction between bytes and unicode; py2 strings are coerced into unicode. I think it would be better to speak about 'JSON string' or 'JSON string element' if it's JSON and about 'unicode' (2.7) or 'str' (3.x) when speaking about the data that has been decoded again. json.loads(json.dumps(boo)) u'boo' json.loads(json.dumps({a: b})) {u'a': u'b'} (the keys will always be unicode in 2.7) -- nosy: +valhallasw ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Bob Ippolito b...@redivi.com added the comment: JP is correct, this is how JSON works. The behavior of coercing keys to strings is often desirable, although I agree it could be confusing if you aren't familiar with the JSON spec. -- components: +Documentation -Library (Lib) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
New submission from Sridhar Ratnakumar sridh...@activestate.com: In [2]: json.dumps({'a': 1, 'b': {'c': 3, None: 5}}) Out[2]: '{a: 1, b: {c: 3, null: 5}}' In [3]: j = json.dumps({'a': 1, 'b': {'c': 3, None: 5}}) In [4]: json.loads(j) Out[4]: {u'a': 1, u'b': {u'c': 3, u'null': 5}} I was surprised to note that None was converted to null instead of null. This happens only in dicts and not, for example, lists: In [5]: json.dumps([None, 1, a]) Out[5]: '[null, 1, a]' -- components: Library (Lib) messages: 90896 nosy: srid severity: normal status: open title: json.dumps converts None to null (not null) type: behavior versions: Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Sridhar Ratnakumar sridh...@activestate.com added the comment: The simplest repro: In [6]: json.dumps({None: 3}) Out[6]: '{null: 3}' In [7]: json.loads(json.dumps({None: 3})) Out[7]: {u'null': 3} -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Changes by Benjamin Peterson benja...@python.org: -- assignee: - bob.ippolito nosy: +bob.ippolito status: open - ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Sridhar Ratnakumar sridh...@activestate.com added the comment: Also repros on 3.0/3.1 -- versions: +Python 3.0, Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Jean-Paul Calderone exar...@divmod.com added the comment: Notice what it does to other dict keys: simplejson.dumps({1: 1}) '{1: 1}' In other words, I don't think this is a bug. It's how JSON works. JSON dict keys are strings *only*. -- nosy: +exarkun ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6566] json.dumps converts None to null (not null)
Sridhar Ratnakumar sridh...@activestate.com added the comment: JSON dict keys are strings *only*. I might be helpful to point this out (along with other caveats) in the standard library documentation for JSON. An explicit mention of ``loads(dumps(x)) != x for certain structures`` would be nice. I, sir, was genuinely surprised to discover this. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6566 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com