-
Notifications
You must be signed in to change notification settings - Fork 147
Implement JSON pretty print #324
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
Conversation
Hi, thanks for the PR! How about enhancing Updated prettyJSONSince Go templates cannot handle errors, it returns the original string if an error occurs. "prettyJSON": func(value any) string {
var data map[string]any
switch v := value.(type) {
case string:
if err := json.Unmarshal([]byte(v), &data); err != nil {
return v
}
case map[string]any:
data = v
default:
return fmt.Sprintf("%v", value)
}
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
return fmt.Sprintf("%v", value)
}
return string(b)
}, Example: Handling JSON strings
Invalid JSON strings (such as
Example: Handling JSON objects
Invalid JSON strings (such as
|
Awesome, will do that. |
@tksm I pushed your suggestion, let me know |
I guess I should update the doc as well, but I want to wait for your review before doing that |
LGTM for the |
📝 I have already removed |
I added some examples in the readme and removed outdated options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hello, I just found this and would love to try to use it but it looks like it hasn't been released. Any chance you could cut a new version? Thanks! |
I've just released a new version. Thanks. https://github.com/stern/stern/releases/tag/v1.32.0 |
Following what has been suggested in #323 I tried to implement a
prettyJSON
template function and apretty
flag for existingjson
.My go skills are near to zero, so forgive me if I wrote bad code. I'm open to suggestions 😉
Basic usage: