diff options
| author | Jeff Carr <[email protected]> | 2024-01-01 15:31:33 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-01 15:31:33 -0600 |
| commit | f1a0d18ac19d0db4f7060ea5a5c662348118e399 (patch) | |
| tree | f2e454da9c3ff512b6548ce741825261178a6a56 /json.go | |
initial commit of cloudflare api
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'json.go')
| -rw-r--r-- | json.go | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,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 +} |
