diff options
| author | Jeff Carr <[email protected]> | 2024-01-01 15:33:08 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-01 15:33:08 -0600 |
| commit | f03f76bc082a245f852dcd0cc52fef9ff48cdc93 (patch) | |
| tree | 5e63087bc7cd1fe22743a4b60d120121ce0f7886 /json.go | |
initial commit
Diffstat (limited to 'json.go')
| -rw-r--r-- | json.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -0,0 +1,24 @@ +package digitalocean + +import ( + "encoding/json" +) + +// formatJSON takes an unformatted JSON string and returns a formatted version. +func FormatJSON(unformattedJSON string) (string, error) { + var jsonData interface{} + + // Decode the JSON string into an interface + err := json.Unmarshal([]byte(unformattedJSON), &jsonData) + if err != nil { + return "", err + } + + // Re-encode the JSON with indentation for formatting + formattedJSON, err := json.MarshalIndent(jsonData, "", " ") + if err != nil { + return "", err + } + + return string(formattedJSON), nil +} |
