Skip to content

gh-91114: Added argument for json dump/dumps to print arrays (from lists and tuples) on one line #31762

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

thedannymarsh
Copy link

@thedannymarsh thedannymarsh commented Mar 8, 2022

If json.dump() or json.dumps() are called with the argument list_oneline=True (where default is False). Then the addition of a newline character and indent spacing between each array element will be skipped.

There may be a better naming for the argument, since the json package will convert both lists and tuples to arrays. Perhaps "array_oneline"?

The following code:

import json
dict = {
        'int':5,
        'str':'test',
        'list':[3,4,5]
        }
print('list_oneline = False')
print(json.dumps(dict,indent=2))
print('list_oneline = True')
print(json.dumps(dict,indent=2,list_oneline=True))

Creates the following output:

list_oneline = False
{
  "int": 5,
  "str": "test",
  "list": [
    3,
    4,
    5
  ]
}
list_oneline = True
{
  "int": 5,
  "str": "test",
  "list": [3,4,5]
}

https://bugs.python.org/issue46958

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@dmarshall-bing

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@arhadthedev arhadthedev changed the title bpo-46958: Added argument for json dump/dumps to print arrays (from lists and tuples) on one line gh-91114: Added argument for json dump/dumps to print arrays (from lists and tuples) on one line Apr 2, 2023
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Apr 2, 2023
@busterbeam
Copy link

Wow! I remember trying to push something a while, back and yea every contributor needs to sign an agreement, just letting you know python org, its not a very streamlined process! Maybe host cpython in your on CVS?

Also this is something I would of liked push to python. there aren't any tools online I know of that do this as well so...

Copy link
Member

@arhadthedev arhadthedev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint / lint (pull_request) check reports formatting issues in its Details section.

@arhadthedev
Copy link
Member

This PR needs additions into Doc/ and Lib/test.

@thedannymarsh
Copy link
Author

thedannymarsh commented Jun 1, 2023

This PR needs additions into Doc/ and Lib/test.

Got it, I'm on it, thanks!

@python python deleted a comment Apr 7, 2025
@python-cla-bot
Copy link

The following commit authors need to sign the Contributor License Agreement:

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review stdlib Python modules in the Lib dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants