Repository navigation
Implement JSON pretty print - #324
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 stringsInvalid JSON strings (such as Example: Handling JSON objectsInvalid 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. |
Co-authored-by: Takashi Kusumi <[email protected]>
|
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
prettyJSONtemplate function and aprettyflag for existingjson.My go skills are near to zero, so forgive me if I wrote bad code. I'm open to suggestions 😉
Basic usage: