helia-json 0.1.2

JSON support for Helia IPFS nodes
Documentation

Helia JSON

JSON support for Helia, providing simple JSON serialization and storage for structured data compatible with IPFS JSON specification.

Example

use helia::create_helia;
use helia_json::{Json, JsonInterface};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct MyData {
    hello: String,
    numbers: Vec<i32>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let helia = create_helia(None).await?;
    let json = Json::new(Arc::new(helia));
    
    let data = MyData {
        hello: "world".to_string(),
        numbers: vec![1, 2, 3],
    };
    
    // Add JSON data
    let cid = json.add(&data, None).await?;
    
    // Retrieve JSON data
    let retrieved: MyData = json.get(&cid, None).await?;
    assert_eq!(data, retrieved);
    
    Ok(())
}