JSON Processing in Rust: serde_json, simd-json, json5 and Other Libraries

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

JSON Processing in Rust: Overview of Key Libraries and Tools



JSON (JavaScript Object Notation) remains one of the most popular formats for data exchange between services, configuration files, and APIs. In the Rust ecosystem, there are several powerful libraries for working with JSON, each solving its own tasks — from maximum performance to ease of development. In this article, we will thoroughly examine the main tools: serde_json, simd-json, json5, jsonwebtoken and show how to use them in real projects.



1. serde_json — The De Facto Standard



serde_json is the primary library for JSON serialization and deserialization in Rust. It is built on top of the serde framework, which allows automatic conversion of Rust data structures to and from JSON.



Installation: add to Cargo.toml:



[dependencies]serde = { version = "1.0", features = ["derive"] }serde_json = "1.0"


Example: Serialization and Deserialization



use serde::{Deserialize, Serialize};use serde_json::Result;

#[derive(Serialize, Deserialize, Debug)]struct User { name: String, age: u8, email: Option<String>,}

fn main() -> Result<()> { let user = User { name: "Anna".to_string(), age: 30, email: Some("anna@example.com".to_string()), };

// Serialize to JSON string let json_string = serde_json::to_string(&user)?; println!("JSON: {}", json_string);

// Deserialize back to struct let deserialized: User = serde_json::from_str(&json_string)?; println!("{:?}", deserialized);

Ok(())}


Features:

  • Support for nested structures, enums, and optional fields.
  • Working with arbitrary JSON via serde_json::Value (enum with variants Null, Bool, Number, String, Array, Object).
  • Custom serializers through attributes #[serde(rename)], #[serde(skip)] and others.
  • Streaming processing for large files.


When to use: for 95% of projects — this is the best choice. It is stable, well-documented, and integrates with any web frameworks (Actix, Rocket, Axum).



2. simd-json — Maximum Performance



simd-json is a library that uses CPU SIMD instructions (Single Instruction, Multiple Data) to accelerate JSON parsing. According to benchmarks, it is 2–3 times faster than serde_json on large data volumes.



Installation:



[dependencies]simd-json = "0.14"


Example: Fast Parsing



use simd_json::prelude::*;use simd_json::BorrowedValue;

fn main() { let mut data = br#"[{"city":"Moscow","temp":22},{"city":"SPb","temp":18}]"#.to_vec(); // Parsing with mutation of input data (for speed) let value: BorrowedValue = simd_json::to_borrowed_value(&mut data).unwrap(); if let Some(arr) = value.as_array() { for item in arr { let city = item.get("city").and_then(|v| v.as_str()).unwrap_or("unknown"); let temp = item.get("temp").and_then(|v| v.as_f64()).unwrap_or(0.0); println!("{}: {}°C", city, temp); } }}


Features:

  • Works only on x86-64 with AVX2 support (modern processors).
  • Requires mutable input data (to avoid unnecessary allocations).
  • Supports streaming parsing and serialization via the simd_json::json! macro.


<

Recommendations