{"record":{"id":"75657d2e33d1ff73","repo":"tonhowtf/omniget","slug":"expected-a-json-array-of-cookie-objects","errorCode":null,"errorMessage":"Expected a JSON array of cookie objects.","messagePattern":"Expected a JSON array of cookie objects\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/cookies/parsers.rs","lineNumber":206,"sourceCode":"    #[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,\n            http_only: parsed.http_only.unwrap_or(false),\n            path: parsed.path.unwrap_or_else(|| \"/\".to_string()),\n            secure: parsed.secure.unwrap_or(false),\n            expires,","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/cookies/parsers.rs#L188-L224","documentation":"parse_json() accepts a JSON array of cookie objects, or a single JSON object (wrapped into a one-element array). Any other top-level JSON value (string, number, bool, null) bails with 'Expected a JSON array of cookie objects.'","triggerScenarios":"Calling parse()/parse_json() with JSON that parses but whose root is a scalar or null — e.g. '\"cookies\"', 'null', or a double-encoded JSON string.","commonSituations":"Extension exported a bare quoted string; file contains 'null' after a failed export; JSON was double-serialized (a string containing JSON) by the caller.","solutions":["Ensure the top-level JSON is an array: [{\"name\":...},...] or a single object {...}.","If the content is a JSON-encoded string, deserialize twice or unwrap the inner JSON first.","Check the exporting tool's format (Edit-This-Cookie / Get-cookies.txt-LOCALLY) and re-export."],"exampleFix":"// before\nparse_json(\"\\\"[{...}]\\\"\")?; // double-encoded string\n// after\nlet inner: String = serde_json::from_str(content)?;\nparse_json(&inner)?;","handlingStrategy":"validation","validationCode":"let v: serde_json::Value = serde_json::from_str(content)?;\nif !matches!(v, serde_json::Value::Array(_) | serde_json::Value::Object(_)) {\n    return Err(anyhow!(\"cookie JSON must be an array or object\"));\n}","typeGuard":null,"tryCatchPattern":"match parsers::parse_json(content) {\n    Err(e) if e.to_string().contains(\"Expected a JSON array\") => show_format_help(),\n    other => other,\n}","preventionTips":["Ensure top-level JSON is an array of cookie objects (or a single object)","Avoid double-encoding JSON strings","Validate exports with a JSON schema before import"],"tags":["cookies","json","parsing","validation"],"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"}