
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-09-22 16:41 byEric Moyer, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 3846 | closed | jeffreyrack,2017-10-01 15:52 | |
| PR 10051 | merged | hongweipeng,2018-10-23 07:11 | |
| Messages (9) | |||
|---|---|---|---|
| msg302755 -(view) | Author: Eric Moyer (Eric Moyer) | Date: 2017-09-22 16:41 | |
json.tool should have the ability to format jsonlines data. It is a very commonly used format in many industries. Right now when given jsonlines (for example): echo -e '{"ingredients":["frog", "water", "chocolate", "glucose"]} | python -m json.toolWorks. But: echo -e '{"ingredients":["frog", "water", "chocolate", "glucose"]}\n{"ingredients":["chocolate","steel bolts"]}' | python -m json.toolReports an error: "Extra data: line 2 column 1 - line 3 column 1 (char 58 - 100)"I propose that the above behavior be retained but: echo -e '{"ingredients":["frog", "water", "chocolate", "glucose"]}\n{"ingredients":"chocolate","steel bolts"}' | python3.7 -m json.tool --jsonlinesShould print:{ "ingredients": [ "frog", "water", "chocolate", "glucose" ]}{ "ingredients": [ "chocolate", "steel bolts" ]}If someone else agrees this is an appropriate enhancement, I can start work on a PR in a couple of weeks. | |||
| msg302781 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2017-09-23 04:55 | |
This seems like a reasonable enhancement. | |||
| msg302783 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-09-23 04:58 | |
Jsonlines is an external to JSON format. You should split the data on lines and pass every line to the JSON parser separately. The same you should do with json.tool.$ echo -e '{"ingredients":["frog", "water", "chocolate", "glucose"]}\n{"ingredients":["chocolate","steel bolts"]}' | while read -r line; do echo -n "$line" | python -m json.tool; done{ "ingredients": [ "frog", "water", "chocolate", "glucose" ]}{ "ingredients": [ "chocolate", "steel bolts" ]} | |||
| msg302785 -(view) | Author: Ezio Melotti (ezio.melotti)*![]() | Date: 2017-09-23 07:39 | |
I agree with Raymond that this is a reasonable request.Even if jsonlines is not part of the JSON specification, the format is quite common, and practicality beats purity (espcially considering that we are just talking about json.tool). | |||
| msg302904 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2017-09-25 02:01 | |
Eric, did you want to write the PR yourself or would you like for Lisa to bring it to fruition? If you're going to do it yourself, Lisa will serve as the primary reviewer (with either Ezio or me doing the final sign-off). | |||
| msg302953 -(view) | Author: Eric Moyer (Eric Moyer) | Date: 2017-09-25 12:39 | |
I planned to write the PR myself, on the principle of "it's my itch, Ishould scratch it." But if you think it is better for someone else to writeit, you know the codebase better than I, and you know how long a PR takesto review/fix. My intention is to help. I'll do whatever is easier for you.On Sep 24, 2017 10:01 PM, "Raymond Hettinger" <report@bugs.python.org>wrote:>> Raymond Hettinger added the comment:>> Eric, did you want to write the PR yourself or would you like for Lisa to> bring it to fruition? If you're going to do it yourself, Lisa will serve> as the primary reviewer (with either Ezio or me doing the final sign-off).>> ----------> assignee: -> lisroach> nosy: +lisroach>> _______________________________________> Python tracker <report@bugs.python.org>> <https://bugs.python.org/issue31553>> _______________________________________> | |||
| msg328290 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2018-10-23 07:23 | |
The output is not a valid JSON format, and is not a valid JSON Lines format. What you are going to do with it? | |||
| msg328396 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2018-10-24 22:23 | |
> The output is not a valid JSON format, and is not a valid JSON Lines format. What you are going to do with it?It looks useful to me to read a nicely indented JSON in the terminal (without specifying an output file). It's more readable that compact JSON on a single line.But should we add an option to write the output on a single line? It would be the opposite of the tool description:"A simple command line interface for json module to validate and *pretty-print* JSON objects." | |||
| msg329411 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2018-11-07 10:09 | |
New changesetf19447994983902aa88362d8fffe645f1ea2f2aa by Serhiy Storchaka (HongWeipeng) in branch 'master':bpo-31553: add --json-lines option to json.tool (#10051)https://github.com/python/cpython/commit/f19447994983902aa88362d8fffe645f1ea2f2aa | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:52 | admin | set | github: 75734 |
| 2018-11-07 10:25:30 | serhiy.storchaka | set | status: open -> closed stage: patch review -> resolved resolution: fixed versions: + Python 3.8, - Python 3.7 |
| 2018-11-07 10:09:37 | serhiy.storchaka | set | messages: +msg329411 |
| 2018-10-24 22:23:52 | vstinner | set | nosy: +vstinner messages: +msg328396 |
| 2018-10-23 07:23:41 | serhiy.storchaka | set | messages: +msg328290 |
| 2018-10-23 07:11:33 | hongweipeng | set | pull_requests: +pull_request9389 |
| 2017-10-01 15:52:50 | jeffreyrack | set | keywords: +patch stage: patch review pull_requests: +pull_request3828 |
| 2017-09-25 12:39:04 | Eric Moyer | set | messages: +msg302953 |
| 2017-09-25 02:01:57 | rhettinger | set | assignee:lisroach messages: +msg302904 nosy: +lisroach |
| 2017-09-23 07:39:33 | ezio.melotti | set | nosy: +ezio.melotti messages: +msg302785 |
| 2017-09-23 04:58:48 | serhiy.storchaka | set | nosy: +serhiy.storchaka messages: +msg302783 |
| 2017-09-23 04:55:43 | rhettinger | set | nosy: +rhettinger messages: +msg302781 |
| 2017-09-22 16:41:06 | Eric Moyer | create | |