Skip to content

Commit

Permalink
avoid unnecessary json decoding/encoding when the value already is a …
Browse files Browse the repository at this point in the history
…string

Signed-off-by: Guilherme Cassolato <[email protected]>
  • Loading branch information
guicassolato committed Nov 4, 2024
1 parent ff2afd9 commit 113717d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func ReplaceJSONPlaceholders(source string, jsonData string) string {
}

func StringifyJSON(data interface{}) (string, error) {
_, ok := data.(string)
if ok {
return data.(string), nil
}
if dataAsJSON, err := json.Marshal(data); err != nil {
return "", err
} else {
Expand Down

0 comments on commit 113717d

Please sign in to comment.