rtk-ai/rtk · error · anyhow::Error
{} is not a JSON file (detected {}). Use `rtk read` for non-
Error message
{} is not a JSON file (detected {}). Use `rtk read` for non-JSON files. What it means
`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`.
Source
Thrown at src/cmds/system/json_cmd.rs:35
"toml" => Some("TOML"),
"yaml" | "yml" => Some("YAML"),
"xml" => Some("XML"),
"csv" => Some("CSV"),
"ini" => Some("INI"),
"env" => Some("env"),
"txt" => Some("plain text"),
_ => None,
};
if let Some(fmt) = format_name {
let mut msg = format!(
"{} is not a JSON file (detected {}). Use `rtk read` for non-JSON files.",
file.display(),
fmt
);
if ext == "toml" && file.file_name().is_some_and(|n| n == "Cargo.toml") {
msg.push_str(" Tip: use `rtk deps` for Cargo.toml.");
}
bail!("{}", msg);
}
}
Ok(())
}
/// Show JSON (compact with values by default, or keys-only with --keys-only)
pub fn run(file: &Path, max_depth: usize, schema_only: bool, verbose: u8) -> Result<()> {
validate_json_extension(file)?;
let timer = tracking::TimedExecution::start();
if verbose > 0 {
eprintln!("Analyzing JSON: {}", file.display());
}
let content = fs::read_to_string(file)
.with_context(|| format!("Failed to read file: {}", file.display()))?;
let shown = render_json(&content, max_depth, schema_only)?;View on GitHub (pinned to 36788f6bd4)
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.
Example fix
# before rtk json config.yaml # after rtk read config.yaml # non-JSON file # or rtk json config.json # actual JSON
Defensive patterns
Strategy: validation
Validate before calling
# check the extension before calling rtk json case "$file" in *.json) rtk json "$file" ;; *) rtk read "$file" ;; esac
Try / catch
# shell if ! rtk json "$file" 2>err.log; then grep -q 'is not a JSON file' err.log && rtk read "$file" fi
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- rtk find does not support compound predicates or actions (e.
- dotnet: no subcommand specified
- gt: no subcommand specified
- go: no subcommand specified
- sbt: no subcommand specified
AI-assisted analysis of rtk-ai/rtk@36788f6bd4 (2026-09-03).
Data as JSON: /api/errors/62ee073abbeeadea.
Report an issue: GitHub.