jlcodes99/cockpit-tools · error
不支持的 JSON 格式 {:?}
Error message
不支持的 JSON 格式 {:?} What it means
import_from_files only supports JSON files whose top-level value is an object or an array of objects. When the parsed file is any other JSON type (string, number, boolean, or bare null), this error is logged and the file cannot be processed as a legacy-rule import. It signals a malformed or wrong-kind of input file, not a token problem.
Source
Thrown at crates/cockpit-core/src/modules/codex_account_core_mutations_quota.rs:73
candidates.push((tokens, hint, filename_label.clone()));
} else {
logger::log_error(&format!("未找到有效 Token {:?}", file_path));
}
}
serde_json::Value::Array(arr) => {
for item in arr {
if let Some((tokens, hint)) = extract_codex_tokens_from_value(item) {
let label = item
.get("email")
.and_then(|v| v.as_str())
.unwrap_or(&filename_label)
.to_string();
candidates.push((tokens, hint, label));
}
}
}
_ => {
logger::log_error(&format!("不支持的 JSON 格式 {:?}", file_path));
}
}
if candidates.len() == before_count {
logger::log_info(&format!(
"Codex 文件旧规则未找到账号,将尝试 Token/JSON 导入逻辑 {:?}",
file_path
));
fallback_files.push((content, filename_label));
}
}
if candidates.is_empty() && fallback_files.is_empty() {
return Err(
"未找到有效的 Codex Token(需要 accessToken/access_token、id_token + access_token,或 refresh_token)"
.to_string(),
);
}View on GitHub (pinned to 1ed8b77992)
Solutions
- Ensure the file contains a JSON object (single account) or array of objects (multiple accounts)
- Wrap a raw token in a JSON object like {"access_token": "..."} before importing
- Re-export/re-download the auth file from the source tool
- Check the file was not truncated or corrupted during transfer
Example fix
// before (token.txt saved as .json)
"eyJhbGciOi..."
// after
{ "access_token": "eyJhbGciOi..." } Defensive patterns
Strategy: validation
Validate before calling
fn is_importable_shape(v: &serde_json::Value) -> bool {
match v {
serde_json::Value::Object(_) => true,
serde_json::Value::Array(a) => a.iter().all(|i| i.is_object()),
_ => false,
}
} Type guard
fn top_level_kind(v: &serde_json::Value) -> &'static str {
match v {
serde_json::Value::Object(_) => "object",
serde_json::Value::Array(_) => "array",
serde_json::Value::String(_) => "string",
serde_json::Value::Number(_) => "number",
serde_json::Value::Bool(_) => "bool",
serde_json::Value::Null => "null",
}
} Prevention
- Never save a raw token string with a .json extension
- Always export/import whole JSON objects or arrays of objects
- Check file contents (first non-whitespace char should be '{' or '[') before import
- Re-export the file if it may have been truncated
When it happens
Trigger: Calling import_from_files on a file whose content is e.g. a bare string, a number, or 'null' — typically a wrong file selected in the import dialog or a file that contains only a pasted token string without JSON object wrapping.
Common situations: User pastes a raw token into a .json file; drag-and-drop of the wrong file; a corrupted/truncated JSON file that parses to a scalar; exporting tool emitted a JSONL or quoted string.
Related errors
- 未找到有效 Token {:?}
- invalidJsonMessage
- messages.rawLineNoRefreshToken(item.lineNumber)
- messages.rawLineMultipleRefreshTokens(item.lineNumber)
- messages.invalidJson
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/9800f087a697a0fc.
Report an issue: GitHub.