New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json.dumps with indent = 0 not adding newlines #54228
Comments
In Python 2.6.4, json.dumps(...,indent=0) produced newlines as documented here: http://docs.python.org/library/json.html#json.dump $ python
Python 2.6.4 (r264:75706, Jan 13 2010, 19:41:08)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.dumps({3:1,4:2},indent=0)
'{\n"3": 1, \n"4": 2\n}'
>>> print json.dumps({3:1,4:2},indent=0)
{
"3": 1,
"4": 2
}
$ python
Python 2.7 (r27:82500, Oct 3 2010, 06:00:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.dumps({3:1,4:2})
'{"3": 1, "4": 2}'
>>> print json.dumps({3:1,4:2},indent=0)
{"3": 1, "4": 2} |
The C encoder should not be used when indent=0. Here is a patch+test for 2.7. |
The test in the patch assumes a specific iteration order for the dict "h", changing the dict to have only one key would fix this problem with the test. |
The test also repeats an equivalent dict to "h" in the check function. |
I just applied a version of this patch with corrections to the tests here: |
+1 to merge simplejson 2.1+ before 3.2 beta 1 (mid-november) |
Hi, As of merging simplejson, it's more a matter of porting it to Python 3. I'll drop an email to Bob soon, let's see how it goes. |
Oh, just to say I took the version as of http://code.google.com/p/simplejson/source/detail?r=234 |
New changeset 8264f68e8251 by R David Murray in branch '2.7': New changeset 4a1048257995 by R David Murray in branch '3.1': New changeset fe8bbaff5a27 by R David Murray in branch '3.2': New changeset 2d0d0850335e by R David Murray in branch 'default': |
Thanks, Sandro. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: