Skip to main content

JsonData

Derive Macro JsonData 

Source
#[derive(JsonData)]
{
    // Attributes available to this derive:
    #[json_data]
}
Expand description

Derive macro that generates JS-compatible JSON serialization for Juno serverless function structs.

Automatically maps Candid types to their JsonData* equivalents (PrincipalJsonDataPrincipal, Vec<u8>JsonDataUint8Array, u64JsonDataBigInt) and generates:

  • into_json_data() — serializes the struct to bytes for passing to the JS runtime
  • from_json_data() — deserializes bytes from the JS runtime back into the struct

§Example

#[derive(CandidType, Serialize, Deserialize, JsonData)]
pub struct InputArgs {
    value: Principal,
}

#[derive(CandidType, Serialize, Deserialize, JsonData)]
pub struct OutputArgs {
    value: Principal,
    text: String,
}

// Generated: InputArgsJsonData/OutputArgsJsonData structs + From impls + into_json_data() + from_json_data()