Skip to main content

Crate file_to_json

Crate file_to_json 

Source
Expand description

file_to_json provides a lightweight façade for converting arbitrary files into JSON.

The crate understands a handful of structured text formats (such as CSV, JSON, YAML, and TOML) and will convert them locally. For unfamiliar formats, it falls back to an LLM via any OpenAI-compatible chat-completions endpoint (OpenRouter, Ollama, etc.).

§Getting started (OpenRouter)

use file_to_json::{Converter, OpenRouterConfig, FallbackStrategy};
use std::time::Duration;

let config = OpenRouterConfig {
    api_key: "sk-or-...".to_string(),
    model: "anthropic/claude-3.7-sonnet".to_string(),
    timeout: Duration::from_secs(60),
    fallback_strategy: FallbackStrategy::Chunked,
    vision_model: Some("anthropic/claude-3.7-sonnet".to_string()),
    max_image_bytes: 5 * 1024 * 1024,
    base_url: None, // uses OpenRouter by default
};
let converter = Converter::new(config)?;
let json_value = converter.convert_path("examples/data.csv")?;
println!("{}", serde_json::to_string_pretty(&json_value)?);

§Using Ollama

use file_to_json::{Converter, OpenRouterConfig, FallbackStrategy};
use std::time::Duration;

let config = OpenRouterConfig {
    api_key: String::new(), // not needed for Ollama
    model: "llama3.3".to_string(),
    timeout: Duration::from_secs(300),
    fallback_strategy: FallbackStrategy::Chunked,
    vision_model: Some("llava".to_string()),
    max_image_bytes: 5 * 1024 * 1024,
    base_url: Some("http://localhost:11434/v1/chat/completions".to_string()),
};
let converter = Converter::new(config)?;

Re-exports§

pub use config::AnthropicConfig;
pub use config::LlmConfig;
pub use config::OpenRouterConfig;
pub use converter::Converter;
pub use errors::ConvertError;
pub use fallback::FallbackStrategy;

Modules§

config
converter
errors
fallback

Constants§

DEFAULT_MAX_IMAGE_BYTES
DEFAULT_MODEL
DEFAULT_VISION_MODEL
MAX_LLM_INPUT_BYTES