I was unclear if you needed to know about just a "quoted string" or if you needed to know about json, or the difference between both of them, so this shows you how to detect both scenarios so you can be very specific.
I posted the interactive code sample here as well: http://play.golang.org/p/VmT0BVBJZ7
package main
import (
"encoding/json"
"fmt"
)
func isJSONString(s string) bool {
var js string
return json.Unmarshal([]byte(s), &js) == nil
}
func isJSON(s string) bool {
var js map[string]interface{}
return json.Unmarshal([]byte(s), &js) == nil
}
func main() {
var tests = []string{
`"Platypus"`,
`Platypus`,
`{"id":"1"}`,
}
for _, t := range tests {
fmt.Printf("isJSONString(%s) = %v
", t, isJSONString(t))
fmt.Printf("isJSON(%s) = %v
", t, isJSON(t))
}
}
Which will output this:
isJSONString("Platypus") = true
isJSON("Platypus") = false
isJSONString(Platypus) = false
isJSON(Platypus) = false
isJSONString({"id":"1"}) = false
isJSON({"id":"1"}) = true