You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Extend json.tool to handle jsonlines (with a flag) #75734
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):
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.
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).
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).
I planned to write the PR myself, on the principle of "it's my itch, I
should scratch it." But if you think it is better for someone else to write
it, you know the codebase better than I, and you know how long a PR takes
to review/fix. My intention is to help. I'll do whatever is easier for you.
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).
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."
Activity
EricMoyer commentedon Sep 22, 2017
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):
Works. But:
Reports an error: "Extra data: line 2 column 1 - line 3 column 1 (char 58 - 100)"
I propose that the above behavior be retained but:
Should 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.
rhettinger commentedon Sep 23, 2017
This seems like a reasonable enhancement.
serhiy-storchaka commentedon Sep 23, 2017
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.
ezio-melotti commentedon Sep 23, 2017
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).
rhettinger commentedon Sep 25, 2017
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).
EricMoyer commentedon Sep 25, 2017
I planned to write the PR myself, on the principle of "it's my itch, I
should scratch it." But if you think it is better for someone else to write
it, you know the codebase better than I, and you know how long a PR takes
to review/fix. My intention is to help. I'll do whatever is easier for you.
On Sep 24, 2017 10:01 PM, "Raymond Hettinger" <[email protected]>
wrote:
serhiy-storchaka commentedon Oct 23, 2018
The output is not a valid JSON format, and is not a valid JSON Lines format. What you are going to do with it?
vstinner commentedon Oct 24, 2018
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."
serhiy-storchaka commentedon Nov 7, 2018
New changeset f194479 by Serhiy Storchaka (HongWeipeng) in branch 'master':
bpo-31553: add --json-lines option to json.tool (bpo-10051)
f194479