Paste Rust on the left and click "Convert" — we will turn it into JSONPaste Rust code

What this tool does

If you have ever defined a struct, slapped #[derive(Serialize)] on it, and realized you just need the JSON without writing the serde boilerplate, adding serde_json to Cargo.toml, and running cargo run — this tool does that. Paste the Rust here and get valid JSON back without touching cargo. It handles a single struct literal, a whole module with several types, or something with deeply nested Vec and Option — same result: a clean JSON document with every field preserved.

The converter tracks how serde actually serializes values. String and &str become JSON strings. i32, u64, f32, f64 all become JSON numbers. bool becomes true/false. Vec<T>, &[T], and [T; N] become JSON arrays. HashMap<String, V> / BTreeMap<String, V> become JSON objects. Option<T> with None becomes JSON null; with Some(value) it serializes the inner type. Tuples come out as heterogeneous arrays — the exact behaviour documented at serde.rs/data-model.

Serde attributes are honoured. #[serde(rename = "x")] renames the JSON key, #[serde(skip)] removes the field, and #[serde(flatten)] lifts nested struct fields to the parent object. enum types follow the externally-tagged representation by default (configurable with #[serde(tag = "type")]). Paste multiple structs at once and each one comes out as a top-level entry. If you are working with web services built on the Rust standard library plus axum/actix, this output drops straight into your integration tests.

How to use it

Three steps. Works the same whether you paste one struct literal or a full module with a dozen types.

1

Paste your Rust (or load the sample)

Drop your Rust into the left editor as-is. A struct, a tuple struct, an enum with variants, multiple types, or nested Vec/Option/HashMap — all fine. Click Load Sample to see a realistic example first.

You do not need to remove use statements, lifetimes, or derive attributes. Leave the Rust syntax as-is — the serde attributes are part of what the parser reads.

2

Hit Convert

Click the green Convert button. The tool reads the Rust, preserves every struct and field, and emits the JSON in one pass. A short loading indicator runs while it works.

3

Copy the JSON

The right panel fills with indented JSON. Copy it into a reqwest test, an axum integration test, your OpenAPI examples, or a curl command. No rebuild needed.

When this actually comes in handy

Web service fixtures

You have an axum or actix request struct and need JSON for a test or a curl call. Paste the struct, grab the JSON, move on — no cargo cycle.

CLI config starters

A clap-driven CLI with a Config struct. Convert it to a JSON template users can edit, without writing a custom <code>Default</code> impl just for docs.

Integration test seeds

Turn the struct literals from your unit tests into JSON seed files for integration tests, mock servers, or embedded-database fixtures.

Docs that track the code

Generate JSON examples for your README or OpenAPI spec straight from the real Rust types, so the docs stop drifting.

Common questions

Do I need serde and serde_json in my Cargo.toml?

Not for this tool — it runs server-side and does not compile your code. For runtime use in your own app, serde with the derive feature plus serde_json is the standard combo.

Does it honour #[serde(rename)], #[serde(skip)], and #[serde(flatten)]?

Yes. #[serde(rename = "x")] renames the JSON key, #[serde(skip)] removes the field from output, and #[serde(flatten)] lifts nested struct fields to the parent — matching the serde field attributes documentation.

How are Option, Vec, and HashMap handled?

Option<T> with None becomes JSON null; with Some(v) it serializes the inner value. Vec<T>, slices, and arrays become JSON arrays. HashMap<String, V> and BTreeMap<String, V> become JSON objects; maps with non-string keys have their keys stringified.

What about enums with variants?

By default, enum variants use the externally-tagged representation ({ "VariantName": {...} }). The #[serde(tag = "type")], #[serde(untagged)], and #[serde(content = "data")] attributes switch to internally-tagged, untagged, or adjacently-tagged — the tool reads those attributes and outputs accordingly.

Is my code stored?

Your code is sent to the backend for conversion and is not persisted — we do not log the payload. Give sensitive code a review before pasting.

What if the Rust uses lifetimes or generics?

Lifetimes (&'a str) are ignored — JSON has no concept of them. Concrete generic types (Vec<User>) work. Uninstantiated generics come out as null. Macros that expand to real syntax work; macros that rely on a proc-macro crate not visible here are treated as opaque.

Other tools you may need

Rust to JSON is one piece of the puzzle. These pair well with it: