I want to create a function to receive an input string which can be string in json format or just a string. For example, something easy like following function.
This might be an older post to the actual function in the standard library.
But you can just use the json.Valid() function in the "encoding/json" package.
var tests = []string{
`"Platypus"`,
`Platypus`,
`{"id":"1"}`,
`{"id":"1}`,
}
for _, t := range tests {
fmt.Printf("is valid: (%s) = %v\n", t, json.Valid([]byte(t)))
}
example https://play.golang.org/p/nfvOzQB919s