{"record":{"id":"5b9b058b1d1e5451","repo":"larksuite/cli","slug":"trailing-data-after-json-value-w","errorCode":null,"errorMessage":"trailing data after JSON value: %w","messagePattern":"trailing data after JSON value: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/sheets/lark_sheet_table_io.go","lineNumber":328,"sourceCode":"\t\treturn \"datetime64[ns]\"\n\tcase \"bool\":\n\t\treturn \"bool\"\n\tdefault:\n\t\treturn \"object\"\n\t}\n}\n\n// decoderExpectEOF ensures the decoder has nothing left to read after a\n// successful Decode. json.Decoder accepts trailing non-whitespace after the\n// first JSON value (unlike json.Unmarshal), so a payload like `{...} trailing`\n// would silently be treated as the leading object only. Use this after the\n// first Decode to surface the trailing data as a validation error.\nfunc decoderExpectEOF(dec *json.Decoder) error {\n\tvar trailing json.RawMessage\n\tif err := dec.Decode(&trailing); err == nil {\n\t\treturn fmt.Errorf(\"trailing data after JSON value\") //nolint:forbidigo // intermediate error; the caller wraps it into a typed --sheets/--values validation error\n\t} else if !errors.Is(err, io.EOF) {\n\t\treturn fmt.Errorf(\"trailing data after JSON value: %w\", err) //nolint:forbidigo // intermediate error; the caller wraps it into a typed --sheets/--values validation error\n\t}\n\treturn nil\n}\n\n// tablePutSheetsSkeleton is the one-line --sheets shape inlined on a decode\n// error, so the retry needs no --print-schema round trip. Field vocabulary\n// mirrors tableSheetIn.\nconst tablePutSheetsSkeleton = `{\"sheets\":[{\"name\":\"Sheet1\",\"columns\":[\"City\",\"Revenue\"],\"dtypes\":{\"Revenue\":\"float64\"},\"data\":[[\"SH\",123.4],[\"BJ\",56.7]],\"start_cell\":\"A1\"}]}`\n\n// parseTablePutPayload reads --sheets (JSON, supports @file / stdin) into a\n// validated payload. UseNumber keeps numeric cells as json.Number so large\n// integers (order IDs, etc.) survive without precision loss or scientific\n// notation. The wire shape (tableSheetIn: string columns + dtypes/formats maps\n// + `data`) is normalized into the internal tableSheetSpec so the rest of the\n// file (buildSheetMatrix, sheetCreateDims, …) is unaware of it. Network-free:\n// safe from Validate and DryRun.\nfunc parseTablePutPayload(runtime flagView) (*tablePayload, error) {\n\traw := strings.TrimSpace(runtime.Str(\"sheets\"))","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/sheets/lark_sheet_table_io.go#L310-L346","documentation":"Same check as errorIndex 951, but here the second Decode failed with an error other than EOF (a JSON syntax error in the trailing bytes). decoderExpectEOF wraps that underlying error to report both the trailing-data condition and the parse failure. Callers wrap it into a typed --sheets/--values validation error.","triggerScenarios":"Payload with malformed bytes after the first JSON value, e.g. '{...} ,,' or '{...} {' — the trailing fragment is itself invalid JSON, so Decode returns a syntax error instead of EOF.","commonSituations":"Truncated copy/paste leaving a partial second object; shell splitting arguments leaving stray '{' or ','; corrupted heredoc input.","solutions":["Delete the malformed trailing fragment after the first complete JSON value","Validate the payload with a JSON linter (jq . payload.json) before passing it","Pass the payload via a file or properly quoted single argument to avoid shell mangling"],"exampleFix":"// before\n--sheets '{\"columns\":[]} {,' \n// after\n--sheets '{\"columns\":[]}'","handlingStrategy":"validation","validationCode":"function assertValidJSON(s) { JSON.parse(s); return s; }\n// run before invoking: assertValidJSON(payload)","typeGuard":"function isParsableJSON(s) { try { JSON.parse(s); return true; } catch { return false; } }","tryCatchPattern":"try {\n  await run(['lark','sheet','table-put','--sheets',payload]);\n} catch (e) {\n  if (/trailing data after JSON value: /.test(e.message)) {\n    console.error('Payload has malformed trailing bytes; validate with jq:', e.message);\n  }\n  throw e;\n}","preventionTips":["Validate payload files with `jq . payload.json` before passing them","Read payloads from a single quoted argument or file, not from concatenated shell fragments","Check heredocs/copy-paste for truncation or duplicated braces"],"tags":["cli","json","validation","syntax"],"backgroundTag":"trailing-data-after-json","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"}