Get field name that is erroneous in Go json unmarshal

I have several large json files that are slightly different in types that contain fields.

{ "a":"1" }

against.

{ "a":1 }

When I cancel the second, I get:

cannot unmarshal number into Go value of type string

However, since these jsons are large, I would like to have an actual field, which is an error, so I can fix them. UnmarshalTypeErrordoes not contain a Struct field type.

Does anyone know how to get to the field name? (not debugging, I have many different fields that are wrong)

[EDIT] I know how to solve type conversion. I need a method to see which fields I need to apply for conversion.

+4
source share
1 answer

The short answer is that you cannot.

, , :

  • json.Unmarshal, : , .
  • thrid-party, , , JSON-, JSON Schema: -, , -
+3

Source: https://habr.com/ru/post/1545353/


All Articles