serde-rs /json

Strongly typed JSON library for Rust

★ 5,672⑂ 737👁 36⑃ 562● 799▤ 184
RustApache-2.0Created 2015-05-19
TA的项目
下载:v1.0.154v1.0.154 ↓1.0.1542026-10-11
+0
日增长
5,672
stars
737
forks
36
watchers
562
prs
799
issues
184
releases

README

Serde JSON   [![Build Status]][actions] [![Latest Version]][crates.io]

[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/json/ci.yml?branch=master
[actions]: https://github.com/serde-rs/json/actions?query=branch%3Amaster
[Latest Version]: https://img.shields.io/crates/v/serde_json.svg
[crates.io]: https://crates.io/crates/serde\_json

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

---

toml
[dependencies]
serde_json = "1.0"


You may be looking for:

- JSON API documentation
- Serde API documentation
- Detailed documentation about Serde
- [Setting up [derive(Serialize, Deserialize)]](https://serde.rs/derive.html)
- Release notes

JSON is a ubiquitous open-standard format that uses human-readable text to
transmit data objects consisting of key-value pairs.

json
{
    "name": "John Doe",
    "age": 43,
    "address": {
        "street": "10 Downing Street",
        "city": "London"
    },
    "phones": [
        "+44 1234567",
        "+44 2345678"
    ]
}


There are three common ways that you might find yourself needing to work with
JSON data in Rust.

 - As text data. An unprocessed string of JSON data that you receive on an
   HTTP endpoint, read from a file, or prepare to send to a remote server.
 - As an untyped or loosely typed representation. Maybe you want to check
   that some JSON data is valid before passing it on, but without knowing the
   structure of what it contains. Or you want to do very basic manipulations
   like insert a key in a particular spot.
 - As a strongly typed Rust data structure. When you expect all or most of
   your data to conform to a particular structure and want to get real work done
   without JSON's loosey-goosey nature tripping you up.

Serde JSON provides efficient, flexible, safe ways of converting data between
each of these representations.

 Operating on untyped JSON values

Any valid JSON data can be manipulated in the following recursive enum
representation. This data structure is [serde_json::Value][value].

rust
enum Value {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec),
    Object(Map),
}


A string of JSON data can be parsed into a serde_json::Value by the
[serde_json::from_str][from_str] function. There is also
[from_slice][from_slice] for parsing from a byte slice &[u8] and
[from_reader][from_reader] for parsing from any io::Read like a File or a
TCP stream.







rust
use serde_json::{Result, Value};

fn untyped_example() - Result {
    // Some JSON input data as a &str. Maybe this comes from the user.
    let data = r"
        {
            "name": "John Doe",
            "age": 43,
            "phones": [
                "+44 1234567",
                "+44 2345678"
            ]
        }";

    // Parse the string of data into serde_json::Value.
    let v: Value = serde_json::from_str(data)?;

    // Access parts of the data by indexing with square brackets.
    p

Top issues

Latest release

v1.0.154 v1.0.154 2026-10-11
- Support preserve_order in no_std builds (1333, thanks @razmser)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON