Golang Json Tag

In which scenarios is the string tag used ? I followed one of the posts and tried using it accordingly but failed.
I shall leave a link to post that I followed:

My way of implementing:

Thanks for the help.

You need to wrap the values in the JSON in strings to be able to parse it when using string:

	msg := `{
		"id": "1",
		"name": "hello",
		"val": "789.33"

From the docs:

The “string” option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types. This extra level of encoding is sometimes used when communicating with JavaScript programs:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.