larksuite/cli · error

value is not JSON-encodable

Error message

value is not JSON-encodable: %w

What it means

compileData rejects a typed data definition that sets both an explicit Output.Data.Shape and Output.Data.Overrides, since a fully explicit shape leaves nothing to override and combining them would be ambiguous. Exactly one authoring style must be chosen.

Solutions

  1. Remove the Overrides entries and keep only the explicit Shape.
  2. Remove the explicit Shape and keep Overrides (struct-derived shape + mutations).
  3. If overrides are meant to refine a struct-derived shape, drop Shape and let compilation derive it from the Data struct type.

Example fix

// before
Definition{Shape: myShape, Overrides: []Override{{Path:"/a", Value:1}}}
// after
Definition{Shape: myShape}
Defensive patterns

Strategy: validation

Validate before calling

func jsonEncodable(v any) error {
  var seen map[uintptr]struct{}
  _, err := json.Marshal(v)
  return err
}

Prevention

When it happens

Trigger: Passing typedDataDefinition with both Shape != nil and len(Overrides) > 0 to compileData (directly or via compileDefinitionParts).

Common situations: Migrating from override-based definitions to explicit shapes and leaving stale overrides in place; copy-pasting a definition and adding a Shape without removing Overrides.

Related errors


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

Appendix: source

Thrown at shortcuts/common/typed_compile_contract.go:209

			object, ok := shapeAsObject(variant)
			if !ok {
				return typedObjectShape{}, false
			}
			if !found {
				combined = object
				found = true
			} else if object.AdditionalProperties {
				combined.AdditionalProperties = true
			}
		}
		return combined, found
	}
	return typedObjectShape{}, false
}
func valueCompatibleWithShape(value any, shape typedValueShape) error {
	encoded, err := json.Marshal(value)
	if err != nil {
		return fmt.Errorf("value is not JSON-encodable: %w", err)
	}
	normalized, err := decodeJSONValidationValue(encoded)
	if err != nil {
		return fmt.Errorf("value is not valid JSON: %w", err)
	}
	return validateJSONValueAgainstShape(normalized, shape, "value")
}

View on GitHub (pinned to 7fd6ef3c07)