{"record":{"id":"303796e95d1b4030","repo":"jlcodes99/cockpit-tools","slug":"invalidjsonmessage","errorCode":null,"errorMessage":"invalidJsonMessage","messagePattern":"invalidJsonMessage","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/useProviderAccountsPage.ts","lineNumber":277,"sourceCode":"};\n\nconst parseLineDelimitedJsonObjects = (\n  rawContent: string,\n  invalidJsonMessage: string,\n): unknown[] | null => {\n  const lines = rawContent\n    .split(/\\r?\\n/)\n    .map((line) => line.trim())\n    .filter((line) => line.length > 0);\n\n  if (lines.length <= 1) return null;\n\n  return lines.map((line) => {\n    let parsed: unknown;\n    try {\n      parsed = JSON.parse(line) as unknown;\n    } catch {\n      throw new Error(invalidJsonMessage);\n    }\n    if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n      throw new Error(invalidJsonMessage);\n    }\n    return parsed;\n  });\n};\n\nconst isCodexDirectImportItem = (value: unknown): boolean => {\n  if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n  const payload = value as Record<string, unknown>;\n  const tokens = payload.tokens;\n  if (\n    typeof payload.id_token === 'string' &&\n    payload.id_token.trim() &&\n    typeof payload.access_token === 'string' &&\n    payload.access_token.trim()\n  ) {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/hooks/useProviderAccountsPage.ts#L259-L295","documentation":"parseLineDelimitedJsonObjects parses multi-line input where each line must be a standalone JSON object. This error is thrown when a line cannot be parsed by JSON.parse (or is not a plain object). The hook falls back to line-delimited parsing only when the whole content is not valid JSON, so hitting this means neither whole-bundle nor line-delimited JSON parsing succeeded.","triggerScenarios":"resolveExternalImportBundleItems fails JSON.parse on the whole content, then the line-delimited fallback parseLineDelimitedJsonObjects encounters a line with invalid JSON syntax (line 277: parse failure).","commonSituations":"Pasting export files where one line is truncated or hand-edited; lines containing unquoted or trailing-comma JSON; mixed content like log lines or comments interleaved with JSON objects; copy-paste losing characters.","solutions":["Check the exact line number in the pasted content and fix its JSON syntax (missing quotes, commas, braces)","Validate each line individually with JSON.parse before pasting","If the content is not JSON (e.g. raw tokens or prose), use the plain refresh-token format instead (codex) or export proper JSON","Ensure each line is a single self-contained JSON object, not an array or comma-joined objects"],"exampleFix":"// before (line 2 invalid)\n{\"refresh_token\":\"rt_a\"}\n{refresh_token: \"rt_b\"}\n// after\n{\"refresh_token\":\"rt_a\"}\n{\"refresh_token\":\"rt_b\"}","handlingStrategy":"validation","validationCode":"const lines = content.split(/\\r?\\n/).map(l => l.trim()).filter(Boolean);\nif (lines.length > 1 && !lines.every(l => { try { const v = JSON.parse(l); return !!v && typeof v === 'object' && !Array.isArray(v); } catch { return false; } })) {\n  throw new Error('Each line must be a valid JSON object');\n}","typeGuard":"const isPlainObject = (v: unknown): v is Record<string, unknown> =>\n  !!v && typeof v === 'object' && !Array.isArray(v);","tryCatchPattern":"try {\n  items = resolveExternalImportBundleItems(content, platformId, messages);\n} catch (e) {\n  if (e instanceof Error && e.message === messages.invalidJson) {\n    showLineByLineJsonHelp(content);\n  }\n}","preventionTips":["Validate each line with JSON.parse before submitting a multi-line paste","Keep one JSON object per line; never split an object across lines","Avoid pasting logs, comments, or prose alongside JSON","Re-export from source rather than hand-editing JSON"],"tags":["json","parsing","import","validation"],"backgroundTag":"invalid-json-input","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}