-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Extend json.tool to handle jsonlines (with a flag) #75734
Comments
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: If someone else agrees this is an appropriate enhancement, I can start work on a PR in a couple of weeks. |
This seems like a reasonable enhancement. |
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"
]
} |
I agree with Raymond that this is a reasonable request. |
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 On Sep 24, 2017 10:01 PM, "Raymond Hettinger" <report@bugs.python.org>
|
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: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: