Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-31553: Add --jsonlines option to json.tool.#3846

Closed
jeffreyrack wants to merge 10 commits into
python:masterpython/cpython:masterfrom
jeffreyrack:bpo31553jeffreyrack/cpython:bpo31553Copy head branch name to clipboard
Closed

bpo-31553: Add --jsonlines option to json.tool.#3846
jeffreyrack wants to merge 10 commits into
python:masterpython/cpython:masterfrom
jeffreyrack:bpo31553jeffreyrack/cpython:bpo31553Copy head branch name to clipboard

Conversation

@jeffreyrack

@jeffreyrack jeffreyrack commented Oct 1, 2017

Copy link
Copy Markdown
Contributor

Add the --jsonlines option to the json.tool utility in order to parse input that is passed using the jsonlines formatting.

https://bugs.python.org/issue31553

https://bugs.python.org/issue31553

Comment thread Lib/json/tool.py Outdated
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 output using the jsonlines format.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think there are three typos here: Parse output -> parse input (the other help texts are not capitalized) and the other texts don't end in a period.

Comment thread Lib/json/tool.py
import json
import sys

def parse_json_from_filehandle(infile, sort_keys):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These functions are a bit repetitive and add a lot of unnecessary lines of code. I think they could be avoided by keeping the functionality in the original location. The code could become more like:

sort_keys = options.sort_keys
jsonlines = options.jsonlines
with infile:
    if jsonlines:
        if sort_keys:
            objs = [json.loads(line) for line in infile]
        else:
           ...
    else:
        if sort_keys:
            objs = [json.load(infile)]
        else:
            ...

This keeps the code more concise.

@jeffreyrack jeffreyrack deleted the bpo31553 branch March 19, 2018 03:49
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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.