2023-12-20 03:13:43 -06:00
|
|
|
// This is a simple example
|
|
|
|
package cloudflare
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
// formatJSON takes an unformatted JSON string and returns a formatted version.
|
2023-12-21 09:39:33 -06:00
|
|
|
func FormatJSON(unformattedJSON string) (string, error) {
|
2023-12-20 03:13:43 -06:00
|
|
|
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
|
|
|
|
}
|