Skip to content

Latest commit

 

History

History
97 lines (47 loc) · 2.46 KB

json.md

File metadata and controls

97 lines (47 loc) · 2.46 KB

Module 0x2::json

Constants

Error if the T is not a struct

const ErrorTypeNotMatch: u64 = 1;

Error if the json string is invalid

const ErrorInvalidJSONString: u64 = 2;

Function from_json

Function to deserialize a type T. The u128 and u256 types must be json String type instead of Number type

#[data_struct(#[T])]
public fun from_json<T: copy>(json_str: vector<u8>): T

Function from_json_option

Function to deserialize a type T. If the json string is invalid, it will return None

#[data_struct(#[T])]
public fun from_json_option<T: copy>(json_str: vector<u8>): option::Option<T>

Function to_map

Parse a json object string to a SimpleMap If the json string is invalid, it will return an empty SimpleMap If the field type is primitive type, it will be parsed to String, array or object will be parsed to json string

Function to_json

Serialize a value of type T to JSON string bytes.

public fun to_json<T>(value: &T): vector<u8>