| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
The change LGTM, but I'm not 100% sure about the usefulness of the feature :-) See discussion at https://bugs.python.org/issue31553
Sorry, something went wrong.
| try: | ||
| obj = json.load(infile) | ||
| if jsonlines: | ||
| objs = [json.loads(line) for line in infile] |
There was a problem hiding this comment.
Instead of loading all lines and only later dump all objects, it may be better to: load on object, dump it, then load the second object, etc.
The behavior difference is that first JSONs are written into outfile if they are valid, but if the last one is invalid. With the current code, it's all-or-nothing. Maybe it's done on purpose?
The other advantage of working on a single object is to reduce the memory footprint when working with large JSON files.
Sorry, something went wrong.
There was a problem hiding this comment.
Good idea.
Just make objs an iterator:
objs = (json.loads(line) for line in infile)or
objs = map(json.loads, infile)
Sorry, something went wrong.
There was a problem hiding this comment.
Wow, that's great. Thank you for your guidance.
Sorry, something went wrong.
| help='write the output of infile to outfile') | ||
| parser.add_argument('--sort-keys', action='store_true', default=False, | ||
| help='sort the output of dictionaries alphabetically by key') | ||
| parser.add_argument('--jsonlines', action='store_true', default=False, |
There was a problem hiding this comment.
I suggest to name the option --json-lines or just --lines.
Sorry, something went wrong.
There was a problem hiding this comment.
--json-lines named similar to the existing --sort-keys,it will be more suitable.
Sorry, something went wrong.
There was a problem hiding this comment.
Needed the documentation and an entry in What's New.
Sorry, something went wrong.
| parser.add_argument('--sort-keys', action='store_true', default=False, | ||
| help='sort the output of dictionaries alphabetically by key') | ||
| parser.add_argument('--jsonlines', action='store_true', default=False, | ||
| help='parse input using the jsonlines format') |
There was a problem hiding this comment.
Maybe 'parse every input line as separate JSON object'?
Sorry, something went wrong.
There was a problem hiding this comment.
Write whatsnew in 3.8?
Sorry, something went wrong.
| try: | ||
| obj = json.load(infile) | ||
| if jsonlines: | ||
| objs = [json.loads(line) for line in infile] |
There was a problem hiding this comment.
Good idea.
Just make objs an iterator:
objs = (json.loads(line) for line in infile)or
objs = map(json.loads, infile)
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
|
|
||
|
|
||
| json.tool | ||
| ------- |
There was a problem hiding this comment.
Add an empty line after "---". And the number of minuses should match the length of the header.
Sorry, something went wrong.
There was a problem hiding this comment.
I have limited knowledge about Doc.Thank you for your patience.
Sorry, something went wrong.
|
|
||
| json.tool | ||
| ------- | ||
| Add option ``--json-lines`` to parse every input line as separate JSON object. |
There was a problem hiding this comment.
Add "(Contributed by ... in :issue:`...`.)"
Sorry, something went wrong.
|
I have made the requested changes; please review again. |
Sorry, something went wrong.
|
Thanks for making the requested changes! @serhiy-storchaka: please review the changes made to this pull request. |
Sorry, something went wrong.
There was a problem hiding this comment.
You can add your full name if you prefer.
Sorry, something went wrong.
|
@matrixise It's my full name :) |
Sorry, something went wrong.
|
ping |
Sorry, something went wrong.
|
@serhiy-storchaka: Please replace # with GH- in the commit message next time. Thanks! |
Sorry, something went wrong.
|
Damn it! I have pressed Enter by mistake while edited commit message. Thank you for your contribution @hongweipeng! |
Sorry, something went wrong.
|
@serhiy-storchaka Oh!It is a beautiful mistake for me. Will you revoke this merger? |
Sorry, something went wrong.
|
It can't be revoked without making larger harm. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
https://bugs.python.org/issue31553