serde_json_wrapper

Crates.ioserde_json_wrapper
lib.rsserde_json_wrapper
version0.1.0
created_at2025-06-28 23:58:29.690588+00
updated_at2025-06-28 23:58:29.690588+00
descriptionSerialize T as a pretty JSON string
homepage
repositoryhttps://github.com/JohnScience/serde_json_wrapper
max_upload_size
id1730210
size10,709
Dmitrii - Demenev (JohnScience)

documentation

https://docs.rs/serde_json_wrapper

README

serde_json_wrapper

Crates.io Downloads Documentation License Dependency Status

This is a simple library that provides a JsonPretty<T> wrapper around any type T that implements serde::Serialize and/or serde::Deserialize. It allows you to serialize and deserialize T as a pretty JSON string (see serde_json::to_string_pretty).

One notable use case is to use it for rendering the JSON representation of T with handlebars::Handlebars::render.

Example

use serde::{Deserialize, Serialize};
use serde_json_wrapper::JsonPretty;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
struct TestStruct {
    field1: String,
    field2: i32,
}

fn main() {
    let test_data = TestStruct {
        field1: "value1".to_string(),
        field2: 42,
    };
    let json_pretty = JsonPretty(test_data);

    let json_value = serde_json::to_value(&json_pretty).unwrap();
    let serde_json::Value::String(serialized) = json_value else {
        panic!("Expected a JSON string");
    };
    let expected = "{\n  \"field1\": \"value1\",\n  \"field2\": 42\n}";
    assert_eq!(serialized, expected);
}
Commit count: 0

cargo fmt