Skip to content
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

gh-126629 Allow the use of strings as loading or saving paths for JSON #126626

Closed
wants to merge 4 commits into from

Conversation

moyanj
Copy link

@moyanj moyanj commented Nov 9, 2024

Allow the use of strings as loading or saving paths for JSON.

It maintains the original API, but allows strings to be passed in when passing in file descriptors.This makes it easy to load or save JSON files.

Just like this:

import json

data = {
    "a":"b"
}
json.dump(data, "a.json")  # before: json.dump(data, open("a.json","w"))

@moyanj moyanj requested a review from a team as a code owner November 9, 2024 15:14
Copy link

cpython-cla-bot bot commented Nov 9, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Nov 9, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@nineteendo
Copy link
Contributor

nineteendo commented Nov 9, 2024

This would need to be discussed on Discourse, just like #117946, https://discuss.python.org/t/file-path-support-for-pickle-dump-and-pickle-load/51488

I do have support for this in my own json library using read() and write(), but I'm not convinced it should be handled in load() and dump() because one argument becomes useless in this case.

@moyanj moyanj changed the title Allow the use of strings as loading or saving paths for JSON gh-126629 Allow the use of strings as loading or saving paths for JSON Nov 9, 2024
@moyanj
Copy link
Author

moyanj commented Nov 9, 2024

I have read some discussions about this issue.I think this is a meaningless pull request, so I will close it

@moyanj moyanj closed this Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants