summaryrefslogtreecommitdiff
path: root/json.go
blob: b7c71a82518f2417cc3fdb4f0c8cd5b1e0808885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// This is a simple example
package cloudflare

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
}