{"record":{"id":"62ee073abbeeadea","repo":"rtk-ai/rtk","slug":"is-not-a-json-file-detected-use-rtk-read","errorCode":null,"errorMessage":"{} is not a JSON file (detected {}). Use `rtk read` for non-JSON files.","messagePattern":"(.+?) is not a JSON file \\(detected (.+?)\\)\\. Use `rtk read` for non-JSON files\\.","errorType":"validation","errorClass":"anyhow::Error","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/36788f6bd4932037caac5cbb1d15d6e2fb9f33da/src/cmds/system/json_cmd.rs#L17-L53","documentation":"`rtk json` only processes JSON files. Before reading the file, `validate_json_extension` checks the extension and rejects known non-JSON formats (TOML, YAML/YML, XML, CSV, INI, env, txt) with a message telling you to use `rtk read` instead. For Cargo.toml specifically it also suggests `rtk deps`.","triggerScenarios":"Running `rtk json file.toml`, `rtk json config.yaml`, `rtk json Cargo.toml`, or any file whose extension maps to a known non-JSON format (toml, yaml, yml, xml, csv, ini, env, txt).","commonSituations":"Pointing rtk json at config files by habit (Cargo.toml, docker-compose.yml, .env), confusing JSON with YAML because they look similar, or batch scripts iterating over mixed config files.","solutions":["Use `rtk read <file>` for non-JSON files — that is the recommended tool for them.","Use `rtk deps` if the target is Cargo.toml and you want dependency info.","Verify the file actually is JSON (correct path/extension); convert YAML/TOML to JSON first if needed.","If the file is truly JSON but has a misleading extension, rename it or pipe its content via stdin instead."],"exampleFix":"# before\nrtk json config.yaml\n\n# after\nrtk read config.yaml   # non-JSON file\n# or\nrtk json config.json   # actual JSON","handlingStrategy":"validation","validationCode":"# check the extension before calling rtk json\ncase \"$file\" in\n  *.json) rtk json \"$file\" ;;\n  *) rtk read \"$file\" ;;\nesac","typeGuard":null,"tryCatchPattern":"# shell\nif ! rtk json \"$file\" 2>err.log; then\n  grep -q 'is not a JSON file' err.log && rtk read \"$file\"\nfi","preventionTips":["Use `rtk json` only for .json files; route TOML/YAML/XML/CSV/INI/env/txt to `rtk read`.","Remember Cargo.toml has a dedicated tool: `rtk deps`.","Never assume YAML is JSON — extensions differ even when content looks similar.","Catch the message pattern 'is not a JSON file' in wrappers to auto-fallback to rtk read."],"tags":["cli","json","file-format","validation"],"backgroundTag":"invalid-file-format","analyzedSha":"36788f6bd4932037caac5cbb1d15d6e2fb9f33da","analyzedAt":"2026-09-03T16:33:57.738Z","contentChangedAt":"2026-09-03T16:33:57.738Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}