diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/structure/normalize_json.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/structure/normalize_json.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/structure/normalize_json.go b/vendor/github.com/hashicorp/terraform/helper/structure/normalize_json.go new file mode 100644 index 0000000..3256b47 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/helper/structure/normalize_json.go | |||
@@ -0,0 +1,24 @@ | |||
1 | package structure | ||
2 | |||
3 | import "encoding/json" | ||
4 | |||
5 | // Takes a value containing JSON string and passes it through | ||
6 | // the JSON parser to normalize it, returns either a parsing | ||
7 | // error or normalized JSON string. | ||
8 | func NormalizeJsonString(jsonString interface{}) (string, error) { | ||
9 | var j interface{} | ||
10 | |||
11 | if jsonString == nil || jsonString.(string) == "" { | ||
12 | return "", nil | ||
13 | } | ||
14 | |||
15 | s := jsonString.(string) | ||
16 | |||
17 | err := json.Unmarshal([]byte(s), &j) | ||
18 | if err != nil { | ||
19 | return s, err | ||
20 | } | ||
21 | |||
22 | bytes, _ := json.Marshal(j) | ||
23 | return string(bytes[:]), nil | ||
24 | } | ||