{"record":{"id":"08d69fe9dce1d08a","repo":"tonhowtf/omniget","slug":"invalid-json-e","errorCode":null,"errorMessage":"invalid JSON: {e}","messagePattern":"invalid JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/cookies/parsers.rs","lineNumber":202,"sourceCode":"    #[serde(default, alias = \"httpOnly\")]\n    http_only: Option<bool>,\n    #[serde(default)]\n    secure: Option<bool>,\n    #[serde(default, alias = \"expirationDate\", alias = \"expires\")]\n    expiration: Option<f64>,\n    name: String,\n    value: String,\n    #[serde(default, alias = \"hostOnly\")]\n    host_only: Option<bool>,\n    #[serde(default, alias = \"sameSite\")]\n    same_site: Option<String>,\n    #[serde(default)]\n    session: Option<bool>,\n}\n\npub fn parse_json(content: &str) -> anyhow::Result<Vec<ExtensionCookie>> {\n    let raw: serde_json::Value =\n        serde_json::from_str(content).map_err(|e| anyhow::anyhow!(\"invalid JSON: {e}\"))?;\n    let arr = match raw {\n        serde_json::Value::Array(a) => a,\n        serde_json::Value::Object(_) => vec![raw],\n        _ => anyhow::bail!(\"Expected a JSON array of cookie objects.\"),\n    };\n    let mut cookies = Vec::with_capacity(arr.len());\n    for item in arr {\n        let parsed: JsonCookie = match serde_json::from_value(item) {\n            Ok(c) => c,\n            Err(_) => continue,\n        };\n        let expires = match (parsed.session.unwrap_or(false), parsed.expiration) {\n            (true, _) => 0,\n            (false, Some(f)) => f as i64,\n            (false, None) => 0,\n        };\n        cookies.push(ExtensionCookie {\n            domain: parsed.domain,","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/cookies/parsers.rs#L184-L220","documentation":"parse_json first deserializes the raw cookie-export content with serde_json::from_str; if the content is not syntactically valid JSON it wraps serde's error as 'invalid JSON: {e}'. This is the outermost gate before the array/object shape check and per-cookie parsing.","triggerScenarios":"Calling parse_json (directly or via parse/parse_for_domain and the parse_json_* wrappers) with content that fails serde_json parsing: empty string, raw Netscape cookie-file text, JSON with trailing commas or comments, HTML error pages pasted instead of the export, BOM-prefixed or truncated files.","commonSituations":"User imports a cookies.txt (Netscape format) file instead of a JSON export; file truncated mid-transfer; editing the export by hand and breaking syntax; clipboard content with surrounding text or smart quotes; empty export from a fresh extension profile.","solutions":["Validate the file is real JSON (e.g. JSON.parse in JS or jq . in shell) before importing.","Export cookies in JSON format from the extension — do not pass cookies.txt / Netscape-format files to parse_json.","Strip a UTF-8 BOM and any leading/trailing whitespace before parsing.","Fix syntax errors named in the message (serde reports line/column) — trailing commas, unquoted keys, comments.","If you need Netscape support, convert cookies.txt to JSON first or add a format-detecting wrapper."],"exampleFix":"// before\nlet cookies = parsers::parse_json(&std::fs::read_to_string(\"cookies.txt\")?)?; // Netscape text\n\n// after\nlet content = std::fs::read_to_string(\"cookies.json\")?;\nlet content = content.trim_start_matches('\\u{feff}');\nserde_json::from_str::<serde_json::Value>(content) // pre-validate\n    .map_err(|e| anyhow::anyhow!(\"cookie export is not valid JSON: {e}\"))?;\nlet cookies = parsers::parse_json(content)?;","handlingStrategy":"validation","validationCode":"function validateCookieExport(text) {\n  const cleaned = text.replace(/^\\uFEFF/, '').trim();\n  if (!cleaned.startsWith('[') && !cleaned.startsWith('{')) {\n    throw new Error('cookie export must be JSON (array or object), not cookies.txt');\n  }\n  JSON.parse(cleaned); // throws with position on syntax errors\n  return cleaned;\n}","typeGuard":"function isCookieJson(text) {\n  try { const v = JSON.parse(text); return Array.isArray(v) || (v && typeof v === 'object'); }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  const cookies = await invoke('parse_cookies', { content: fileText });\n} catch (e) {\n  if (String(e).startsWith('invalid JSON:')) {\n    showError('The selected file is not valid JSON. Export cookies as JSON, not cookies.txt.');\n  } else throw e;\n}","preventionTips":["Only import JSON-format cookie exports, never Netscape cookies.txt","Strip BOM and whitespace before parsing","Hand edits to exports should be re-validated with a JSON linter","Detect file format by sniffing the first character before calling parse_json"],"tags":["cookies","json","parse-error","import"],"backgroundTag":"json-parse-error","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}