larksuite/cli · error
value is not valid JSON: %w
Error message
value is not valid JSON: %w
What it means
After successfully JSON-encoding the value, valueCompatibleWithShape decodes it via decodeJSONValidationValue to get a normalized JSON document for shape validation; if that decode fails, the value (or its marshaled form) is not valid JSON for validation purposes and this wrapped error is returned.
Source
Thrown at shortcuts/common/typed_compile_contract.go:213
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)
Solutions
- Fix the custom MarshalJSON so it emits well-formed JSON (use json.Marshal on a plain representation inside it).
- Replace NaN/Inf values with nil or a sentinel JSON value before validation.
- Inspect the wrapped %w cause to find the exact decode failure, then correct the offending value.
Example fix
// before
func (v Value) MarshalJSON() ([]byte, byte) { return []byte(v.Raw), nil } // Raw may be invalid
// after
func (v Value) MarshalJSON() ([]byte, error) { return json.Marshal(v.Raw) } Defensive patterns
Strategy: validation
Validate before calling
func validMarshalOutput(v json.Marshaler) error {
b, err := v.MarshalJSON()
if err != nil { return err }
var out any
return json.Unmarshal(b, &out)
} Prevention
- Prefer embedding a plain struct and delegating to json.Marshal inside custom marshalers
- Reject NaN/Inf at value construction time
- Round-trip test every custom MarshalJSON: marshal then unmarshal
When it happens
Trigger: An override Value whose json.Marshal output is rejected by decodeJSONValidationValue — e.g. a MarshalJSON emitting malformed JSON text, or emitting types the decoder refuses (invalid UTF-8, NaN/Inf smuggled through custom marshaling).
Common situations: Hand-rolled MarshalJSON returning invalid JSON strings; custom marshalers emitting NaN/Infinity for float fields; corrupted values produced by third-party types with buggy marshalers.
Related errors
- malformed config
- app registration failed: response missing device_code
- json pointer must start with '/' or be empty, got %q
- SecretRef.source must be env|file|exec, got %q
- SecretRef.id must be non-empty
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/cbe60924b26676df.
Report an issue: GitHub.