MCPcopy Create free account
hub / github.com/apache/openwhisk-cli / getFormattedJSON

Function getFormattedJSON

commands/util.go:141–157  ·  view source on GitHub ↗
(key string, value string)

Source from the content-addressed store, hash-verified

139}
140
141func 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
159func getEscapedJSON(value string) string {
160 value = strings.Replace(value, "\\", "\\\\", -1)

Callers 7

getKeyValueArgsFunction · 0.85
feedParametersFunction · 0.85
trigger.goFile · 0.85
CreateMethod · 0.85
CreateExtendedVersionFunction · 0.85
UpdateMethod · 0.85
UpdateExtendedVersionFunction · 0.85

Calls 2

getEscapedJSONFunction · 0.85
isValidJSONFunction · 0.85

Tested by

no test coverage detected