summaryrefslogtreecommitdiff
path: root/json.go
diff options
context:
space:
mode:
Diffstat (limited to 'json.go')
-rw-r--r--json.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/json.go b/json.go
new file mode 100644
index 0000000..c0aa1a8
--- /dev/null
+++ b/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
+}