(key string, value string)
| 139 | } |
| 140 | |
| 141 | func getFormattedJSON(key string, value string) string { |
| 142 | var res string |
| 143 | |
| 144 | key = getEscapedJSON(key) |
| 145 | |
| 146 | if isValidJSON(value) { |
| 147 | whisk.Debug(whisk.DbgInfo, "Value '%s' is valid JSON.\n", value) |
| 148 | res = fmt.Sprintf("{\"%s\": %s}", key, value) |
| 149 | } else { |
| 150 | whisk.Debug(whisk.DbgInfo, "Converting value '%s' to a string as it is not valid JSON.\n", value) |
| 151 | res = fmt.Sprintf("{\"%s\": \"%s\"}", key, value) |
| 152 | } |
| 153 | |
| 154 | whisk.Debug(whisk.DbgInfo, "Formatted JSON '%s'\n", res) |
| 155 | |
| 156 | return res |
| 157 | } |
| 158 | |
| 159 | func getEscapedJSON(value string) string { |
| 160 | value = strings.Replace(value, "\\", "\\\\", -1) |
no test coverage detected