larksuite/cli · error

invalid JSON: multiple values

Error message

invalid JSON: multiple values

What it means

After decoding the first JSON value successfully, decodeCompiledValue decodes again and expects io.EOF. If a second value decodes cleanly, the input contained multiple top-level JSON values (e.g. '{} {}'), which is rejected as 'invalid JSON: multiple values'.

Source

Thrown at shortcuts/common/typed_binder.go:180

		if !ok {
			encoded, err := json.Marshal(raw)
			if err != nil {
				return nil, err
			}
			text = string(encoded)
		}
		value := reflect.New(field.valueType)
		decoder := json.NewDecoder(strings.NewReader(text))
		if objectShape, ok := shapeAsObject(field.shape); ok && !objectShape.AdditionalProperties {
			decoder.DisallowUnknownFields()
		}
		if err := decoder.Decode(value.Interface()); err != nil {
			return nil, fmt.Errorf("invalid JSON: %w", err)
		}
		var trailing any
		if err := decoder.Decode(&trailing); err != io.EOF {
			if err == nil {
				return nil, fmt.Errorf("invalid JSON: multiple values")
			}
			return nil, fmt.Errorf("invalid JSON trailing content: %w", err)
		}
		return value.Elem().Interface(), nil
	}
	return convertReflectValue(raw, field.valueType)
}

func convertReflectValue(raw any, target reflect.Type) (any, error) {
	if raw == nil {
		return nil, nil
	}
	rawValue := reflect.ValueOf(raw)
	if rawValue.Type().AssignableTo(target) {
		return raw, nil
	}
	if target == jsonRawMessageType {
		encoded, err := json.Marshal(raw)

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Ensure exactly one top-level JSON value (wrap multiple objects in an array if the schema allows)
  2. For JSON-Lines files, parse line-by-line and send one value per call, or convert to a JSON array
  3. Trim trailing garbage from generated JSON

Example fix

// before
--data '{"a":1} {"b":2}'
// after
--data '[{"a":1},{"b":2}]'
Defensive patterns

Strategy: validation

Validate before calling

const vals = text.split(/\n(?=\s*\{)/); if (vals.length > 1) throw new Error('single JSON value required'); JSON.parse(text)

Type guard

func isSingleJSONValue(s string) bool { d := json.NewDecoder(strings.NewReader(s)); var v any; if d.Decode(&v) != nil { return false }; return d.Decode(&struct{}{}) == io.EOF }

Try / catch

if strings.Contains(err.Error(), "multiple values") { /* convert NDJSON to a JSON array before retrying */ }

Prevention

When it happens

Trigger: Concatenated JSON documents in a JSON input flag, e.g. --data '{} {}' or '--items [1] [2]'; accidental pasting of two JSON blobs; a file passed to JSON input that contains multiple newline-separated JSON objects.

Common situations: NDJSON/JSON-Lines files supplied where a single JSON value is expected; copy-paste of two examples; script concatenating outputs without a comma.

Understand the failure class

Related errors


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