From ffd9b8633132d5f79ebba6d0640d2d1a6d377abe Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 24 Aug 2018 11:43:44 -0700 Subject: [PATCH] crictl: Fallback if info key is not JSON This allows info map to support non JSON keys Signed-off-by: Mrunal Patel --- cmd/crictl/util.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/crictl/util.go b/cmd/crictl/util.go index bea06d4c04..d0c98e0f29 100644 --- a/cmd/crictl/util.go +++ b/cmd/crictl/util.go @@ -222,7 +222,13 @@ func outputStatusInfo(status string, info map[string]string, format string) erro jsonInfo := "{" + "\"status\":" + status + "," for _, k := range keys { - jsonInfo += "\"" + k + "\"" + ":" + info[k] + "," + var res interface{} + // We attempt to convert key into JSON if possible else use it directly + if err := json.Unmarshal([]byte(info[k]), res); err != nil { + jsonInfo += "\"" + k + "\"" + ":" + "\"" + info[k] + "\"," + } else { + jsonInfo += "\"" + k + "\"" + ":" + info[k] + "," + } } jsonInfo = jsonInfo[:len(jsonInfo)-1] jsonInfo += "}"