{"record":{"id":"8b17aae7798860cf","repo":"larksuite/cli","slug":"invalid-json-multiple-values","errorCode":null,"errorMessage":"invalid JSON: multiple values","messagePattern":"invalid JSON: multiple values","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_binder.go","lineNumber":180,"sourceCode":"\t\tif !ok {\n\t\t\tencoded, err := json.Marshal(raw)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\ttext = string(encoded)\n\t\t}\n\t\tvalue := reflect.New(field.valueType)\n\t\tdecoder := json.NewDecoder(strings.NewReader(text))\n\t\tif objectShape, ok := shapeAsObject(field.shape); ok && !objectShape.AdditionalProperties {\n\t\t\tdecoder.DisallowUnknownFields()\n\t\t}\n\t\tif err := decoder.Decode(value.Interface()); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid JSON: %w\", err)\n\t\t}\n\t\tvar trailing any\n\t\tif err := decoder.Decode(&trailing); err != io.EOF {\n\t\t\tif err == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid JSON: multiple values\")\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"invalid JSON trailing content: %w\", err)\n\t\t}\n\t\treturn value.Elem().Interface(), nil\n\t}\n\treturn convertReflectValue(raw, field.valueType)\n}\n\nfunc convertReflectValue(raw any, target reflect.Type) (any, error) {\n\tif raw == nil {\n\t\treturn nil, nil\n\t}\n\trawValue := reflect.ValueOf(raw)\n\tif rawValue.Type().AssignableTo(target) {\n\t\treturn raw, nil\n\t}\n\tif target == jsonRawMessageType {\n\t\tencoded, err := json.Marshal(raw)","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_binder.go#L162-L198","documentation":"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'.","triggerScenarios":"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.","commonSituations":"NDJSON/JSON-Lines files supplied where a single JSON value is expected; copy-paste of two examples; script concatenating outputs without a comma.","solutions":["Ensure exactly one top-level JSON value (wrap multiple objects in an array if the schema allows)","For JSON-Lines files, parse line-by-line and send one value per call, or convert to a JSON array","Trim trailing garbage from generated JSON"],"exampleFix":"// before\n--data '{\"a\":1} {\"b\":2}'\n// after\n--data '[{\"a\":1},{\"b\":2}]'","handlingStrategy":"validation","validationCode":"const vals = text.split(/\\n(?=\\s*\\{)/); if (vals.length > 1) throw new Error('single JSON value required'); JSON.parse(text)","typeGuard":"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 }","tryCatchPattern":"if strings.Contains(err.Error(), \"multiple values\") { /* convert NDJSON to a JSON array before retrying */ }","preventionTips":["Never concatenate JSON documents; wrap in an array","Convert JSON-Lines files to arrays before sending","Trim generated output to a single document"],"tags":["json","input-parsing"],"backgroundTag":"invalid-json-input","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}