larksuite/cli · error

%s field %s JSON name %q duplicates field %s

Error message

%s field %s JSON name %q duplicates field %s

What it means

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.

Source

Thrown at shortcuts/common/typed_compile_data.go:224

		name := parts[0]
		if name == "-" {
			continue
		}
		if name == "" {
			return typedObjectShape{}, fmt.Errorf("%s field %s json tag must explicitly name the field", path, field.Name)
		}
		omitempty := false
		for _, option := range parts[1:] {
			switch option {
			case "omitempty":
				omitempty = true
			case "":
			default:
				return typedObjectShape{}, fmt.Errorf("%s field %s has unsupported json option %q", path, field.Name, option)
			}
		}
		if previous, exists := seen[name]; exists {
			return typedObjectShape{}, fmt.Errorf("%s field %s JSON name %q duplicates field %s", path, field.Name, name, previous)
		}
		seen[name] = field.Name
		schema, err := parseSchemaTag(field.Tag.Get("schema"), field.Type, input)
		if err != nil {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): %w", path, field.Name, name, err)
		}
		if !input && schema.defaultValue.Set {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): Data field cannot declare default", path, field.Name, name)
		}
		if schema.required && omitempty {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): required Data field cannot use omitempty", path, field.Name, name)
		}
		if schema.optional && !omitempty {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): optional Data field must use omitempty", path, field.Name, name)
		}
		if isNilCapable(field.Type) && schema.nullable == nil {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): nil-capable field must declare nullable or nonnullable", path, field.Name, name)
		}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Rename one of the JSON names so each is unique within the struct
  2. Remove or mark `json:"-"` on the redundant duplicate field
  3. Delete the leftover duplicated field if it is a copy-paste remnant

Example fix

// before
ID string `json:"id"`
IDAlt string `json:"id"`
// after
ID string `json:"id"`
IDAlt string `json:"id_alt"`
Defensive patterns

Strategy: validation

Validate before calling

seen := map[string]string{}
for i := 0; i < t.NumField(); i++ {
    f := t.Field(i)
    name := strings.Split(f.Tag.Get("json"), ",")[0]
    if prev, dup := seen[name]; dup {
        return fmt.Errorf("json name %q duplicated by %s and %s", name, prev, f.Name)
    }
    seen[name] = f.Name
}

Prevention

When it happens

Trigger: 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.

Common situations: 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`.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/d48fa103796de7c0. Report an issue: GitHub.