github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/azurerm/structure.go (about)

     1  package azurerm
     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  }