liveBook · Manning

JSON

As explained in Refactoring to Rust

JSON is a text-based data interchange format representing structured values such as objects, arrays, strings, numbers, booleans, and null.

JSON is a text-based format for structured values. In Rust, Serde maps JSON to typed data structures, while serde_json connects Serde’s generic model to JSON. section 6.3

A small Rust parsing workflow:

  • Define a struct matching the JSON fields, such as name: String and value: i32. section 6.3
  • Add serde_json and enable Serde’s derive feature in Cargo.toml. section 6.3
  • Derive Debug and serde::Deserialize, then parse with serde_json::from_str and an explicit target type. section 6.3
  • Treat mismatched field types as errors; unwrap can panic when parsing fails. section 6.3

Typed JSON parsing

Given { "name": "Rachelle Ferguson", "value": 948129 }, parsing into Data produces Data { name: "Rachelle Ferguson", value: 948129 }. The parsed fields can then support ordinary Rust computation. section 6.3

Figure 6.1 The Serde ecosystem
figure

Use the ecosystem diagram to distinguish Serde’s generic serialization traits from serde_json’s JSON bridge. section 6.3

How Refactoring to Rust covers it

How deep it goes
Explains typed parsing, derived traits, compiler diagnostics, and runtime mismatches, but stops short of advanced format handling.
Examples
Demonstrates name-and-value objects, derived Data structs, parsing errors, and a Rust function matching a Python calculation.
What it assumes
Assumes basic Rust structs and Cargo while teaching Serde derives, generic parsing, and JSON-to-type matching.
What you can do after
Apply it via serde_json to deserialize JSON strings into Rust structs and use the resulting fields.
How it connects
Connects JSON with Serde, serde_json, Rust structs, Cargo, and TOML dependency configuration.

Also explained in

Compare how 35 books explain JSON →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.