serde_json gives you a Value or a struct from the same call
Strongly typed JSON library for Rust
At a glance
- What is it?
- The JSON half of the Serde framework for Rust, parsing text into either a recursive Value enum or a derived struct. The same from_str call produces both, and the choice decides whether a mistyped field name is a compile error or a silent Null at runtime.
- Who is it for?
- serde_json fits a Rust program that receives JSON from a file, a socket or an HTTP endpoint and would rather have the compiler catch a field typo than discover a Null at runtime. Reach for Value only when the shape is genuinely unknown, such as a validity check on data you pass straight through, and move to a derived struct as soon as the shape is known.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 30 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- serde-rs/json5,672 ★ · +34
| Repository | 2026-09-28 | 2026-11-15 |
|---|---|---|
| serde-rs/json | 5.6k | 5.7k |
34 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
One parse call, three ways to hold the data
The README sorts the problem into three representations, and the crate is the bridge between them. The first is text data: an unprocessed JSON string received from an HTTP endpoint, read from a file, or prepared to send to a remote server. The second is an untyped or loosely typed representation, for checking that data is valid before passing it on without knowing its structure, or for basic manipulations such as inserting a key in a particular spot. The third is a strongly typed Rust data structure, for when you expect the data to conform to a particular layout. All of any valid JSON can be held in one recursive enum, serde_json::Value:
enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
Array(Vec<Value>),
Object(Map<String, Value>),
}The parse itself is one function, serde_json::from_str, with from_slice for a byte slice and from_reader for anything that implements io::Read, such as a File or a TCP stream. Which representation you get is decided by the type you assign the result to.
A wrong key in a Value is a Null, not an error
The indexing rules are the part worth memorising before you build anything on Value. Indexing with square brackets returns a borrow of the data at that position, so the type is &Value. A JSON map is indexed with string keys and a JSON array with integer keys. If the type of the data does not match the type you are indexing with, or the map does not contain the key, or the index into the vector is out of bounds, the returned element is Value::Null. Nothing is raised, nothing panics, nothing logs. The README is blunt about the consequence: this representation is fine for very basic tasks and tedious for anything more significant, error handling is verbose to implement correctly, and the compiler is powerless to help you when you make a mistake, with v["name"] typoed as v["nmae"] in one of the dozens of places it appears in a codebase as the example. A missing field and a field holding JSON null arrive at the same place, which is the failure mode to design around.
Printing a Value keeps the JSON quotation marks
Display and logging have their own small trap. When a Value is printed it is printed as a JSON string, so the output of the README's own example reads Please call "John Doe" at the number "+44 1234567", quotation marks included. The reason is that v["name"] is a &Value holding a JSON string, and its JSON representation is the quoted form. Getting a plain string out takes an extra step: converting from the JSON string to a Rust string with as_str(), or not using Value at all and taking the typed route. In practice this matters wherever a Value meets anything a human reads, from a log line to an error message to a field written into a response. It also means a formatted interpolation such as println! with {} on a Value is not a formatting bug, it is the documented representation, and the quotes are there on purpose.
With a struct, the typo moves to compile time
The typed route uses the same function and changes only the target type. A struct annotated with the derive macros, a name: String, an age: u8 and a phones: Vec<String>, is what from_str now produces, and Serde interprets the input as that struct and produces informative error messages if the layout does not conform to what the struct is expected to look like. Any type implementing Deserialize can be deserialized this way, which includes the standard library types Vec<T> and HashMap<K, V> as well as any struct or enum annotated with #[derive(Deserialize)]. The payoff is stated in terms of tooling: the IDE can autocomplete field names to prevent typos, which was impossible in the Value representation, and the compiler can check that when you write p.phones[0], p.phones is guaranteed to be a Vec<String>, so indexing it makes sense and produces a String. The setup for the derive macros is documented on Serde's site rather than here.
The manifest offers two licences and the tree ships both
There is a small mismatch worth noticing if you are choosing a licence to depend on. The crate manifest states license = "MIT OR Apache-2.0", and the root of the repository carries both LICENSE-MIT and LICENSE-APACHE. The licence field on the repository itself is recorded as Apache-2.0 alone. For a dependant the manifest is the grant that ships with the package, so the choice between the two texts is yours. The rest of the manifest is more informative than the README: the crate is named serde_json at version 1.0.154, the documentation link points at docs.rs/serde_json, the repository is listed as https://github.com/serde-rs/json, and the categories include encoding, parser-implementations and no-std. The edition is 2021 and rust-version is 1.71, which sets the floor for the compiler you can build this with.
Default features mean std, and neither std nor alloc works
The feature list is small and carries an explicit warning:
[features]
default = ["std"]
std = ["memchr/std", "serde_core/std"]The default is std, and enabling it forwards to the std feature of the two dependencies that have one. A comment in the manifest describes a further feature that provides integration for heap-allocated collections without depending on the rest of the Rust standard library. Two more feature sets live in the manifest's metadata rather than in the feature list itself. The documentation build is configured with preserve_order, raw_value and unbounded_depth, and the playground with float_roundtrip, raw_value and unbounded_depth, so the two published environments are not built with the same set you get locally.
Five dependencies, one scoped to a target that never builds
The dependency block is short enough to read in full:
[dependencies]
foldhash = { version = "0.2", optional = true, default-features = false }
indexmap = { version = "2.2.3", optional = true, default-features = false }
itoa = "1.0"
memchr = { version = "2", default-features = false }
serde_core = { version = "1.0.220", default-features = false }
zmij = "1.0"
[target.'cfg(any())'.dependencies]
serde = { version = "1.0.220", default-features = false }indexmap and foldhash are the optional ones. memchr and serde_core both disable their default features, which is what lets the std feature be forwarded to them later. The second block is the oddity: it is scoped to the target cfg(any()), which matches no real target, so that entry never contributes to an ordinary build, while still pinning a serde version in the manifest. Development adds more: automod, indoc, ref-cast, rustversion, serde with the derive feature, serde_bytes, serde_derive, serde_stacker and trybuild with the diff feature, which is how compile failures get compared. The root also holds build.rs, a fuzz directory, tests/ and CONTRIBUTING.md.
Three patch releases in 2026, and the last push in August
The version history is a steady line of patch releases rather than a new major: v1.0.152 on 2026-10-10, v1.0.153 on 2026-10-11 and v1.0.154 on 2026-10-11, the last of which is the version in the manifest. The repository is not archived, the default branch is master, and the last push is dated 2026-10-16. Two other details are worth noting. One is in the manifest: it depends on serde_core, not on serde directly, and the versions are not aligned with the dev-dependency on serde. The other is the split between the two documentation surfaces, with JSON API documentation, Serde API documentation, the Serde site, a page on setting up the derive macros and the release notes all linked from the top. Pick the one that matches the problem: the crate reference or the framework.
Editorial conclusion
serde_json fits a Rust program that receives JSON from a file, a socket or an HTTP endpoint and would rather have the compiler catch a field typo than discover a Null at runtime. Reach for Value only when the shape is genuinely unknown, such as a validity check on data you pass straight through, and move to a derived struct as soon as the shape is known. Before you pin a version, note that the crate requires Rust 1.71 or newer and is offered under MIT OR Apache-2.0 while the repository licence field names Apache-2.0 alone.
Frequently asked questions
How does serde.JSON work?
It converts between three representations of the same data: raw JSON text, an untyped serde_json::Value built from a recursive enum, and a strongly typed Rust struct. A single function, serde_json::from_str, does the parsing, with from_slice for byte slices and from_reader for anything implementing io::Read, and the type you assign the result to decides which representation you get.
What is serde used for?
Serde is a framework for serializing and deserializing Rust data structures efficiently and generically, and serde_json is its JSON implementation. Any type implementing Deserialize can be parsed this way, including the built-in Vec<T> and HashMap<K, V> as well as any struct or enum annotated with #[derive(Deserialize)].
What is the purpose of serde in Rust?
It moves the interpretation of input data out of your hands and into a trait implementation, so a struct decides the shape and the error messages come with it. The concrete payoff is tooling: the IDE autocompletes field names, which was impossible with the untyped Value, and the compiler checks that p.phones is a Vec<String>, so p.phones[0] produces a String.
What does "serialized JSON" mean?
JSON is an open-standard format that uses human-readable text to transmit data objects consisting of key-value pairs. Serializing is turning a Rust data structure into that text and deserializing is parsing the text back, either into a Value or into a typed struct, and the crate describes itself as providing efficient, flexible and safe ways of converting between those representations.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/serde-rs-json)Star history chart for your README
[](https://hysenlabs.com/projects/serde-rs-json)Was this useful?