larksuite/cli · error

%s field %s has unsupported json option %q

Error message

%s field %s has unsupported json option %q

What it means

A `json` tag on a struct field contained an option other than `omitempty` (or an empty option slot). The typed data compiler only supports `omitempty` as a tag option, so options like `string`, `minimize`, or unknown names are rejected to keep compiled schema semantics fully defined.

Source

Thrown at shortcuts/common/typed_compile_data.go:220

		if !ok {
			return typedObjectShape{}, fmt.Errorf("%s field %s must declare json tag", path, field.Name)
		}
		parts := strings.Split(rawJSON, ",")
		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)

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Remove the unsupported option, keeping only the name (and `omitempty` if the field is optional)
  2. Fix typos in `omitempty`
  3. If the option encodes schema behavior (e.g. string rendering), express it via the separate `schema:` tag instead

Example fix

// before
Amount int `json:"amount,string"`
// after
Amount int `json:"amount" schema:"required" doc:"..."`
Defensive patterns

Strategy: validation

Validate before calling

for i := 0; i < t.NumField(); i++ {
    f := t.Field(i)
    for _, opt := range strings.Split(f.Tag.Get("json"), ",")[1:] {
        switch opt {
        case "", "omitempty":
        default:
            return fmt.Errorf("field %s has unsupported json option %q", f.Name, opt)
        }
    }
}

Prevention

When it happens

Trigger: A field tagged e.g. `json:"name,omitempty,string"` or `json:"name,minimize"` compiled through compileStructShape.

Common situations: Copying tags from code that uses Go 1.21+ `omitempty` variants or third-party JSON libraries (`string`, `minimize`); typos such as `omitemptyx`; hand-written tags with stray extra words.

Related errors


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