{"record":{"id":"9da3693618cde690","repo":"mikefarah/yq","slug":"unrecognised-type-v","errorCode":null,"errorMessage":"unrecognised type :( %v","messagePattern":"unrecognised type :\\( (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/candidate_node_json.go","lineNumber":42,"sourceCode":"\t\to.Value = fmt.Sprintf(\"%v\", value)\n\t\to.Tag = \"!!float\"\n\t\t// json decoder returns ints as float.\n\t\tif value == float64(int64(rawData.(float64))) {\n\t\t\t// aha it's an int disguised as a float\n\t\t\to.Tag = \"!!int\"\n\t\t\to.Value = fmt.Sprintf(\"%v\", int64(value.(float64)))\n\t\t}\n\tcase int, int64, int32:\n\t\to.Value = fmt.Sprintf(\"%v\", value)\n\t\to.Tag = \"!!int\"\n\tcase bool:\n\t\to.Value = fmt.Sprintf(\"%v\", value)\n\t\to.Tag = \"!!bool\"\n\tcase string:\n\t\to.Value = rawData\n\t\to.Tag = \"!!str\"\n\tdefault:\n\t\treturn fmt.Errorf(\"unrecognised type :( %v\", rawData)\n\t}\n\treturn nil\n}\n\nfunc (o *CandidateNode) UnmarshalJSON(data []byte) error {\n\tlog.Debug(\"UnmarshalJSON\")\n\tswitch data[0] {\n\tcase '{':\n\t\tlog.Debug(\"UnmarshalJSON -  its a map!\")\n\t\t// its a map\n\t\to.Kind = MappingNode\n\t\to.Tag = \"!!map\"\n\n\t\tdec := json.NewDecoder(bytes.NewReader(data))\n\t\t_, err := dec.Token() // open object\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/candidate_node_json.go#L24-L60","documentation":"setScalarFromJson converts a decoded JSON scalar (interface{}) into a CandidateNode scalar and only understands nil, float, int, bool and string. If the JSON unmarshalling layer produces any other Go type (unexpected map/slice reaching the scalar path, or a new numeric type from a JSON library change), it returns 'unrecognised type :( %v'. This indicates the decoder met a value type it has no mapping for.","triggerScenarios":"Unmarshalling JSON into CandidateNode (UnmarshalJSON → setScalarFromJson) where a scalar token decodes to an unsupported Go type — e.g. very large numbers decoded as json.Number, or library changes where nested arrays/maps are passed into the scalar path instead of being handled earlier.","commonSituations":"Using a custom or patched JSON decoder (goccy/go-json version changes) that yields json.Number instead of float64; feeding JSON whose structure hits an untested decoder edge (e.g. non-standard numeric formats); embedding yq's CandidateNode UnmarshalJSON in Go code with data produced by another serializer.","solutions":["Normalise the input before decoding: ensure numbers are plain JSON numbers and scalars are standard JSON types.","If using a custom decoder, configure it to return float64/int64 rather than json.Number (or add a json.Number case to setScalarFromJson and rebuild).","Update (or pin) the yq/goccy-go-json versions to a known-good pairing; check for an existing upstream fix for the type in question.","As a workaround, pre-convert the data with `yq -p json -o json` to canonicalise it before the failing code path."],"exampleFix":"// before (custom decode producing json.Number)\nvar n json.Number = \"123\" // hits default: unrecognised type :( 123\n// after: use standard float decoding\nvar n float64 = 123 // tagged !!int by setScalarFromJson","handlingStrategy":"validation","validationCode":"// Ensure JSON scalars are standard before unmarshalling into CandidateNode\nfor _, v := range rawValues {\n    switch v.(type) {\n    case nil, bool, string, float64, float32, int, int64, int32:\n        // ok\n    default:\n        return fmt.Errorf(\"unsupported scalar %T\", v)\n    }\n}","typeGuard":"func isSupportedJSONScalar(v interface{}) bool {\n    switch v.(type) {\n    case nil, bool, string, float64, float32, int, int64, int32:\n        return true\n    }\n    return false\n}","tryCatchPattern":"// Go\nif err := node.UnmarshalJSON(data); err != nil {\n    if strings.Contains(err.Error(), \"unrecognised type :(\") {\n        // fall back to canonicalising the JSON first\n        return decodeViaCanonicalJSON(data)\n    }\n    return err\n}","preventionTips":["Avoid custom JSON decoders that emit json.Number for scalars","Keep goccy/go-json and yq versions pinned together","Round-trip exotic data through `yq -p json -o json` before decoding"],"tags":["go","yq","json","deserialization"],"backgroundTag":"json-unsupported-type","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}