{"record":{"id":"2b46545af975d879","repo":"larksuite/cli","slug":"invalid-json-trailing-content-w","errorCode":null,"errorMessage":"invalid JSON trailing content: %w","messagePattern":"invalid JSON trailing content: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_binder.go","lineNumber":182,"sourceCode":"\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)\n\t\tif err != nil {\n\t\t\treturn nil, err","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_binder.go#L164-L200","documentation":"When the second decoder pass fails with a non-nil, non-EOF error, the input had one valid JSON value followed by unparseable trailing bytes; it is reported as 'invalid JSON trailing content: %w' wrapping the decoder error.","triggerScenarios":"Trailing characters after valid JSON, e.g. --data '{\"a\":1} extra', stray text appended by a shell redirect, or a BOM/whitespace-embedded comment after the JSON body.","commonSituations":"Appending notes after JSON in scripts; editor saving extra content; $(cat f) expansions concatenating files.","solutions":["Remove everything after the closing brace/bracket of the JSON value","Check the source file for trailing junk (cat -A file) and trim it","Pipe through jq to normalize: jq -c . file"],"exampleFix":"// before\n--data '{\"a\":1} // done'\n// after\n--data '{\"a\":1}'","handlingStrategy":"validation","validationCode":"JSON.parse(text.trim()) // in shell: jq -e . <<< \"$DATA\" >/dev/null","typeGuard":"func hasTrailingContent(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(), \"trailing content\") { /* inspect raw input for junk after the JSON value */ }","preventionTips":["Trim trailing whitespace/comments from generated JSON","Avoid $(cat f) expansions that concatenate files","Pipe through jq to normalize before passing"],"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"}