{"record":{"id":"a030a5d1c8a69207","repo":"rtk-ai/rtk","slug":"is-not-a-json-file-detected-use-rtk-read-for-non-json-files","errorCode":null,"errorMessage":"{} is not a JSON file (detected {}). Use `rtk read` for non-JSON files. Tip: use `rtk deps` for Cargo.toml.","messagePattern":"(.+?) is not a JSON file \\(detected (.+?)\\)\\. Use `rtk read` for non-JSON files\\. Tip: use `rtk deps` for Cargo\\.toml\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/system/json_cmd.rs","lineNumber":35,"sourceCode":"            \"toml\" => Some(\"TOML\"),\n            \"yaml\" | \"yml\" => Some(\"YAML\"),\n            \"xml\" => Some(\"XML\"),\n            \"csv\" => Some(\"CSV\"),\n            \"ini\" => Some(\"INI\"),\n            \"env\" => Some(\"env\"),\n            \"txt\" => Some(\"plain text\"),\n            _ => None,\n        };\n        if let Some(fmt) = format_name {\n            let mut msg = format!(\n                \"{} is not a JSON file (detected {}). Use `rtk read` for non-JSON files.\",\n                file.display(),\n                fmt\n            );\n            if ext == \"toml\" && file.file_name().is_some_and(|n| n == \"Cargo.toml\") {\n                msg.push_str(\" Tip: use `rtk deps` for Cargo.toml.\");\n            }\n            bail!(\"{}\", msg);\n        }\n    }\n    Ok(())\n}\n\n/// Show JSON (compact with values by default, or keys-only with --keys-only)\npub fn run(file: &Path, max_depth: usize, schema_only: bool, verbose: u8) -> Result<()> {\n    validate_json_extension(file)?;\n    let timer = tracking::TimedExecution::start();\n\n    if verbose > 0 {\n        eprintln!(\"Analyzing JSON: {}\", file.display());\n    }\n\n    let content = fs::read_to_string(file)\n        .with_context(|| format!(\"Failed to read file: {}\", file.display()))?;\n\n    let shown = render_json(&content, max_depth, schema_only)?;","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/system/json_cmd.rs#L17-L53","documentation":"`rtk json` only processes files whose extension identifies a JSON format (.json, .jsonc, .json5). When given another extension it bails, telling you to use `rtk read` for plain files — and if it detects a TOML file named Cargo.toml it additionally points you at the purpose-built `rtk deps` command.","triggerScenarios":"Running `rtk json <file>` where <file> ends in .toml, .yaml, .yml, .txt, etc.; calling validate_json_extension directly with a non-JSON path; explicitly rejected cases covered by tests: any .toml file, Cargo.toml specifically, and .yaml files.","commonSituations":"Typing `rtk json Cargo.toml` out of habit instead of `rtk deps`; pointing the json filter at a YAML config because the content looks structured; automating over a directory of mixed config files without checking extensions first.","solutions":["For Cargo.toml use `rtk deps` (the dedicated manifest reader).","For non-JSON files use `rtk read <file>` to view content with filtering.","Verify the file extension/correct path — you may have grabbed the wrong file when two similarly named configs exist (.json vs .yaml).","If the file genuinely is JSON, rename or fix the extension so it matches its content."],"exampleFix":"// before\nrtk json Cargo.toml\n// after\nrtk deps Cargo.toml   # or: rtk read config.yaml for non-JSON files","handlingStrategy":"validation","validationCode":"const JSON_EXTS = new Set(['.json', '.jsonc', '.json5']);\nfunction ensureJsonFile(path) {\n  const ext = path.slice(path.lastIndexOf('.'));\n  if (!JSON_EXTS.has(ext)) {\n    throw new Error(`${path} is not JSON; use rtk deps for Cargo.toml, rtk read otherwise`);\n  }\n  return path;\n}","typeGuard":"fn is_json_file(p: &Path) -> bool {\n    matches!(p.extension().and_then(|e| e.to_str()), Some(\"json\") | Some(\"jsonc\") | Some(\"json5\"))\n}","tryCatchPattern":"match rtk_json(file) {\n    Err(e) if e.to_string().contains(\"is not a JSON file\") => {\n        let ext = file.extension().unwrap_or_default();\n        if file.ends_with(\"Cargo.toml\") { run(\"rtk deps Cargo.toml\")?; }\n        else { run(&format!(\"rtk read {}\", file.display()))?; }\n    }\n    other => other?,\n}","preventionTips":["Check the file extension before routing to `rtk json`; use `rtk deps` for Cargo.toml and `rtk read` for everything else.","In batch jobs, filter the file list to *.json/*.jsonc/*.json5 first.","Keep .json and .yaml config twins clearly named to avoid grabbing the wrong file."],"tags":["cli","json","file-extension","validation"],"backgroundTag":"incompatible-source-type","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}