Crates.io | keyvalues3 |
lib.rs | keyvalues3 |
version | 1.1.0 |
created_at | 2025-06-26 13:10:30.286334+00 |
updated_at | 2025-07-11 14:40:48.481582+00 |
description | A Rust library and CLI tool for parsing, formatting, and converting Valve's KeyValues3 (KV3) text format. |
homepage | |
repository | https://github.com/TheCursedApple/KeyValues3 |
max_upload_size | |
id | 1727276 |
size | 6,312,873 |
A Rust library and CLI tool for parsing and manipulating Valve's KeyValues3 (KV3) format. KV3 is a data serialization format used in games like Dota 2, CS2, and Deadlock. This tool allows you to parse KV3 files, format them with proper indentation, and convert them to JSON.
To use the CLI tool, download the pre-built binary for your operating system from the GitHub releases page. Extract the binary and place it in a directory included in your system's PATH.
To use keyvalues3
as a library in your Rust project, add the following to your Cargo.toml
:
[dependencies]
keyvalues3 = "1.0.0"
For JSON conversion support, enable the "json" feature:
[dependencies]
keyvalues3 = { version = "1.0.0", features = ["json"] }
The CLI tool, named kv3
, provides two primary commands: format
and convert
. Use the --input
option to specify the KV3 file to process.
The format
command reformats a KV3 file with proper indentation and line breaks.
Usage:
kv3-cli --input <input_file> format [--output <output_file>]
--input
: Path to the input KV3 file (required).--output
: Path to save the formatted KV3 (optional; defaults to stdout).The convert
command converts a KV3 file to JSON.
Usage:
kv3-cli --input <input_file> convert [--output <output_file>]
--input
: Path to the input KV3 file (required).--output
: Path to save the JSON output (optional; defaults to stdout).Format a KV3 file and print to the console:
kv3-cli --input example.kv3 format
Format a KV3 file and save to a new file:
kv3-cli --input example.kv3 format --output formatted.kv3
Convert a KV3 file to JSON and print to the console:
kv3-cli --input example.kv3 convert
Convert a KV3 file to JSON and save to a new file:
kv3-cli --input example.kv3 convert --output example.json
The keyvalues3
crate provides functions to parse, format, and convert KV3 data programmatically in Rust.
Use kv3::from_str
to parse a KV3 string into a Value
enum:
use kv3::{from_str, Value};
let kv3_str = r#"
<!-- kv3 encoding:text:version{211C2728-7EE6-4494-BDC9-65496C10E5FD} format:generic:version{6E663C66-2F27-4609-90A4-0E0A731B0A3D} -->
{
key = "value"
}
"#;
let value: Value = from_str(kv3_str).expect("Failed to parse KV3");
Use kv3::to_string
to convert a Value
back into a formatted KV3 string:
use kv3::to_string;
let formatted_kv3 = to_string(&value);
println!("{}", formatted_kv3);
With the "json" feature enabled, use kv3::to_json
to convert a Value
to a serde_json::Value
:
use kv3::to_json;
use serde_json::Value as JsonValue;
let json_value: JsonValue = to_json(&value);
println!("{}", json_value);
Ensure the "json" feature is enabled in your Cargo.toml
as shown in the installation section.
To build the CLI tool from source, ensure you have Rust 1.87 or later installed. Clone the repository and run:
cargo build --release --features binary,json
The binary will be located at target/release/kv3-cli
. Copy it to a directory in your PATH for easy access.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.