{"record":{"id":"d48fa103796de7c0","repo":"larksuite/cli","slug":"s-field-s-json-name-q-duplicates-field-s","errorCode":null,"errorMessage":"%s field %s JSON name %q duplicates field %s","messagePattern":"(.+?) field (.+?) JSON name %q duplicates field (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_data.go","lineNumber":224,"sourceCode":"\t\tname := parts[0]\n\t\tif name == \"-\" {\n\t\t\tcontinue\n\t\t}\n\t\tif name == \"\" {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s json tag must explicitly name the field\", path, field.Name)\n\t\t}\n\t\tomitempty := false\n\t\tfor _, option := range parts[1:] {\n\t\t\tswitch option {\n\t\t\tcase \"omitempty\":\n\t\t\t\tomitempty = true\n\t\t\tcase \"\":\n\t\t\tdefault:\n\t\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s has unsupported json option %q\", path, field.Name, option)\n\t\t\t}\n\t\t}\n\t\tif previous, exists := seen[name]; exists {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s JSON name %q duplicates field %s\", path, field.Name, name, previous)\n\t\t}\n\t\tseen[name] = field.Name\n\t\tschema, err := parseSchemaTag(field.Tag.Get(\"schema\"), field.Type, input)\n\t\tif err != nil {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): %w\", path, field.Name, name, err)\n\t\t}\n\t\tif !input && schema.defaultValue.Set {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): Data field cannot declare default\", path, field.Name, name)\n\t\t}\n\t\tif schema.required && omitempty {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): required Data field cannot use omitempty\", path, field.Name, name)\n\t\t}\n\t\tif schema.optional && !omitempty {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): optional Data field must use omitempty\", path, field.Name, name)\n\t\t}\n\t\tif isNilCapable(field.Type) && schema.nullable == nil {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): nil-capable field must declare nullable or nonnullable\", path, field.Name, name)\n\t\t}","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_data.go#L206-L242","documentation":"Two fields in the same struct compile to the same JSON name, so the produced schema would contain duplicate object keys. The compiler tracks each JSON name (`seen` map) and fails when a second field reuses one, since downstream serialization/lookup would be ambiguous.","triggerScenarios":"Two fields tagged with the same name, e.g. `json:\"id\"` on two different fields, or one field `json:\"id\"` and another `json:\"id,omitempty\"`, compiled via compileData/shapeForType.","commonSituations":"Copy-pasting a field and forgetting to update the tag; renames where the new field reuses an old tag name; a field tagged `json:\"data\"` inside a struct that also has an embedded-like field named `data`.","solutions":["Rename one of the JSON names so each is unique within the struct","Remove or mark `json:\"-\"` on the redundant duplicate field","Delete the leftover duplicated field if it is a copy-paste remnant"],"exampleFix":"// before\nID string `json:\"id\"`\nIDAlt string `json:\"id\"`\n// after\nID string `json:\"id\"`\nIDAlt string `json:\"id_alt\"`","handlingStrategy":"validation","validationCode":"seen := map[string]string{}\nfor i := 0; i < t.NumField(); i++ {\n    f := t.Field(i)\n    name := strings.Split(f.Tag.Get(\"json\"), \",\")[0]\n    if prev, dup := seen[name]; dup {\n        return fmt.Errorf(\"json name %q duplicated by %s and %s\", name, prev, f.Name)\n    }\n    seen[name] = f.Name\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name json tags after the field and keep them unique","Search the struct for the tag name before reusing it","Keep a test that compiles every typed struct to catch duplicates"],"tags":["go","struct-tags","json","duplicate-key"],"backgroundTag":"duplicate-json-key","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}