larksuite/cli · error

value is not valid JSON

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.

Solutions

  1. Fix the custom MarshalJSON so it emits well-formed JSON (use json.Marshal on a plain representation inside it).
  2. Replace NaN/Inf values with nil or a sentinel JSON value before validation.
  3. 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

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


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

Appendix: 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)