Skip to content
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

json pretty print #84

Merged
merged 2 commits into from
Feb 17, 2023
Merged

json pretty print #84

merged 2 commits into from
Feb 17, 2023

Conversation

waclaw66
Copy link
Contributor

@waclaw66 waclaw66 commented Dec 7, 2022

No description provided.

@JOJ0
Copy link
Owner

JOJ0 commented Dec 7, 2022

please post an example of the difference so I might merge it right away.
afk, cant test
cheers!

@waclaw66
Copy link
Contributor Author

waclaw66 commented Dec 7, 2022

json.dumps outputs everything inline, I've added indentation for human reading

original

{"media": [{"media_id": "SFZOcLZamWeKnsnJrfqwfcxr", "media_type": "image/jpeg", "media_length": 344120, "upload_name": "LcV3Ep_YqlJss9A_G8i6", "created_ts": "2022-06-10 16:47:37", "last_access_ts": "2022-11-07 15:01:55", "quarantined_by": null, "safe_from_quarantine": false}, {"media_id": "OgKciuaCYxnBMiiHXXcWqzKP", "media_type": "image/png", "media_length": 786276, "upload_name": "99HFJP4R6Kjvbp9NR0_y", "created_ts": "2022-01-18 17:26:20", "last_access_ts": "2022-04-08 11:04:19", "quarantined_by": null, "safe_from_quarantine": false}], "total": 2}

updated

{
    "media": [
        {
            "media_id": "SFZOcLZamWeKnsnJrfqwfcxr",
            "media_type": "image/jpeg",
            "media_length": 344120,
            "upload_name": "LcV3Ep_YqlJss9A_G8i6",
            "created_ts": "2022-06-10 16:47:37",
            "last_access_ts": "2022-11-07 15:01:55",
            "quarantined_by": null,
            "safe_from_quarantine": false
        },
        {
            "media_id": "OgKciuaCYxnBMiiHXXcWqzKP",
            "media_type": "image/png",
            "media_length": 786276,
            "upload_name": "99HFJP4R6Kjvbp9NR0_y",
            "created_ts": "2022-01-18 17:26:20",
            "last_access_ts": "2022-04-08 11:04:19",
            "quarantined_by": null,
            "safe_from_quarantine": false
        }
    ],
    "total": 2
}

@JOJ0
Copy link
Owner

JOJ0 commented Dec 7, 2022

Oh, alright that's looking nice but actually we have -o pprint for human readable output. You tried that?

Main question being with your change to json output: Will this still be batch-processable? I.e piping to jq for example? Thats the most important usecase for json out.

@waclaw66
Copy link
Contributor Author

waclaw66 commented Dec 7, 2022

Oh, alright that's looking nice but actually we have -o pprint for human readable output. You tried that?

Yes, it's readable, but it's not json.

Main question being with your change to json output: Will this still be batch-processable? I.e piping to jq for example? Thats the most important usecase for json out.

Yes, jq works fine, I've tested it.
synadm media list -u '<user_id>' | jq -c '.media[].media_id' from previous example returns

"SFZOcLZamWeKnsnJrfqwfcxr"
"OgKciuaCYxnBMiiHXXcWqzKP"

@JOJ0
Copy link
Owner

JOJ0 commented Dec 8, 2022

I wonder if -o pprint should implement the pretty-printed-json you suggest here and json should stay json in a single string (as-is). What do you think?

I am not sure if -o pprint as it's currently implemented has any other purpose to users than just to look nice....

On the other hand, changing it might break existing behaviour in case people have shell scripts that depend on how exactly -o pprint currently looks like for further processing.

Not sure how to proceed. What's your opinion?

@waclaw66
Copy link
Contributor Author

waclaw66 commented Dec 8, 2022

I see two options how to proceed in case you want to keep the compatibility and current behaviour.

  • add a new output format "json_pretty"
  • or better add a new universal argument "--pretty" for any output format, that make output format human readible

However I don't see any problem with multiline json string, yaml is also multiline.

@JOJ0
Copy link
Owner

JOJ0 commented Dec 13, 2022

Hi and sorry for the delay. Do you mind joining #synadm:peek-a-boo.at, we were discussing on what's the best way to proceed here. Some valuable opinions and suggestions there. If that's not possible for you at this time, no worries, I'll get back here with a final word on what we decided is best for the project / for users. Thanks for your patience!

@JOJ0
Copy link
Owner

JOJ0 commented Dec 15, 2022

Hi @waclaw66, again: Sorry for the delay and blocking your efforts. I think we have a decision. We'd like to extend this PR to result in the following:

Original json mode changes to the pretty version

synadm -o json / synadm -o j

and creating one for the oneline/minified version:

synadm -o jsonm / synadm -o jm

After your changes are through I will take the task of improving synadm --help to be explicit about what the difference between json and jsonm output modes is. If you feel like it you could include that in this PR but it's certainly not required to finally merge this. I'll take care of that.

@JOJ0
Copy link
Owner

JOJ0 commented Dec 15, 2022

Also just to be complete here, I'd like to answer to your suggestions:

I see two options how to proceed in case you want to keep the compatibility and current behaviour.

  • add a new output format "json_pretty"

Good idea and we discussed it in #synadm. In the end renaming the original minified json to something and making the prettified version the new default seems to be the better idea on the long run.

  • or better add a new universal argument "--pretty" for any output format, that make output format human readible

In don't think that's a possible solution since --pretty does not make sense with formats that are already human readable, thus this could be more confusing than helpful. For example: -o yaml --pretty or -o human --pretty would not really make sense.

However I don't see any problem with multiline json string, yaml is also multiline.

Yes you are right, for most cases and users this seems to be the best solution. For maximum flexibility or possibly performace-critical use-cases, keeping the minified json an option could be helpful.

@JOJ0
Copy link
Owner

JOJ0 commented Jan 3, 2023

Hi @waclaw66, just want to check in and ask if you still have these requested changes on your radar (#84 (comment)) and whether you plan to submit them? No hurry, since it's not a critical bug fix but a new feature: If you manage to submit during some time in January it's perfectly fine. If you don't find the time until then please give us a heads up. Cheers!

@JOJ0
Copy link
Owner

JOJ0 commented Jan 3, 2023

@JOJ0
Copy link
Owner

JOJ0 commented Jan 23, 2023

Hi @waclaw66, friendly reminder :-) Will you have time for finishing this PR or would you rather prefer we finish it ourselves. Any answer is ok and just better than no answer at all. Hope you understand! :-) Thanks and all the best!

@waclaw66
Copy link
Contributor Author

Hi @JOJ0, I'm sorry for the late response, please finish it on your own. Currently I'm quite busy. Thanks for understanding.

@JOJ0
Copy link
Owner

JOJ0 commented Feb 8, 2023

Hi @waclaw66, again: Sorry for the delay and blocking your efforts. I think we have a decision. We'd like to extend this PR to result in the following:

Original json mode changes to the pretty version

synadm -o json / synadm -o j

and creating one for the oneline/minified version:

synadm -o jsonm / synadm -o jm

After your changes are through I will take the task of improving synadm --help to be explicit about what the difference between json and jsonm output modes is. If you feel like it you could include that in this PR but it's certainly not required to finally merge this. I'll take care of that.

I think I'll reconsider here just a little. jsonmini is probably better and even self-descriptive-enough I guess, for minified json. The short version jm still is there if we want to spare some typing time: synadm -o jsonmini / synadm -o jm

@JOJ0 JOJ0 merged commit f2eabca into JOJ0:master Feb 17, 2023
@JOJ0
Copy link
Owner

JOJ0 commented Feb 17, 2023

I will finalize this feature in master....or rather in our dev branch....soon...

JOJ0 added a commit that referenced this pull request Feb 17, 2023
- Keep -o json as the new default as the PR suggests.
- Add a new mode -o jsonmini that still outputs oneline-json as the original
  json output mode did.
- Improve handling of help text. We didn't have any description of the modes
  with the global --output flag. It was hidden with the config -o subcommand.
  It's shown in both places now.
JOJ0 added a commit that referenced this pull request Feb 24, 2023
Finalize PR #84 and improve --output helptext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants