diff options
| author | Jeff Carr <[email protected]> | 2023-12-30 20:47:14 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-12-30 20:47:14 -0600 |
| commit | eb007d63d92280b95a6a79c6c83341870312ccd6 (patch) | |
| tree | c2780b17b140e38d033aded99dcb08f54ee5bc65 /digitalocean/json.go | |
| parent | a117923b327d0d5a74ef64b51082e2ec4bcd9cfd (diff) | |
display droplets
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'digitalocean/json.go')
| -rw-r--r-- | digitalocean/json.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/digitalocean/json.go b/digitalocean/json.go new file mode 100644 index 0000000..c0aa1a8 --- /dev/null +++ b/digitalocean/json.go @@ -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 +} |
