Skip to content

cast: rpc --json should format as json #10871

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented Jun 28, 2025

Motivation

Seems the --json arg is not enabled for cast rpc, it always return a long string whether or not --json was enabled.

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@DaniPopes
Copy link
Member

i mean it's already json, i don't know if it makes much sense to use --json as a pretty flag, in any case you can serde_json::to_string_pretty directly in the cast rpc function

@jsvisa
Copy link
Contributor Author

jsvisa commented Jun 28, 2025

Yeah, you can pass the result to json pretty tools(eg: jq), but if we can directly format them, then no need to relay on 3rd tools. As in some workflows, we need the sudo permission to install every software, so if cast can directly format it, it will be more useful.

And the behavior of cast call will also pretty print the json result:

} else if shell::is_json() {
let tokens = decoded.iter().map(format_token_raw).collect::<Vec<_>>();
serde_json::to_string_pretty(&tokens).unwrap()
} else {

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

imo this is okay, this is more or less the same as | jq

since we have this same behaviour elsewhere already I'm okay with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants