tonhowtf/omniget · error
Expected a JSON array of cookie objects.
Error message
Expected a JSON array of cookie objects.
What it means
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.'
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.
Example fix
// before
parse_json("\"[{...}]\"")?; // double-encoded string
// after
let inner: String = serde_json::from_str(content)?;
parse_json(&inner)?; Defensive patterns
Strategy: validation
Validate before calling
let v: serde_json::Value = serde_json::from_str(content)?;
if !matches!(v, serde_json::Value::Array(_) | serde_json::Value::Object(_)) {
return Err(anyhow!("cookie JSON must be an array or object"));
} Try / catch
match parsers::parse_json(content) {
Err(e) if e.to_string().contains("Expected a JSON array") => show_format_help(),
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Extension exported a bare quoted string; file contains 'null' after a failed export; JSON was double-serialized (a string containing JSON) by the caller.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- No valid cookies found in file (expected Netscape format)
- Unrecognized cookie format. Accepted: Netscape (yt-dlp)…
- Unrecognized cookie format. Accepted: Netscape (yt-dlp)…
- Target domain is required for Cookie header import.
- invalid domain
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/75657d2e33d1ff73.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/src/cookies/parsers.rs:206
#[serde(default, alias = "expirationDate", alias = "expires")]
expiration: Option<f64>,
name: String,
value: String,
#[serde(default, alias = "hostOnly")]
host_only: Option<bool>,
#[serde(default, alias = "sameSite")]
same_site: Option<String>,
#[serde(default)]
session: Option<bool>,
}
pub fn parse_json(content: &str) -> anyhow::Result<Vec<ExtensionCookie>> {
let raw: serde_json::Value =
serde_json::from_str(content).map_err(|e| anyhow::anyhow!("invalid JSON: {e}"))?;
let arr = match raw {
serde_json::Value::Array(a) => a,
serde_json::Value::Object(_) => vec![raw],
_ => anyhow::bail!("Expected a JSON array of cookie objects."),
};
let mut cookies = Vec::with_capacity(arr.len());
for item in arr {
let parsed: JsonCookie = match serde_json::from_value(item) {
Ok(c) => c,
Err(_) => continue,
};
let expires = match (parsed.session.unwrap_or(false), parsed.expiration) {
(true, _) => 0,
(false, Some(f)) => f as i64,
(false, None) => 0,
};
cookies.push(ExtensionCookie {
domain: parsed.domain,
http_only: parsed.http_only.unwrap_or(false),
path: parsed.path.unwrap_or_else(|| "/".to_string()),
secure: parsed.secure.unwrap_or(false),
expires,View on GitHub (pinned to 8600b91f42)