#weird json

10 messages · Page 1 of 1 (latest)

pale ingot
#

Have you looked into serde_json

#

The Value enum is able to hold both strings and numbers

reef shell
#

enum

#

enum Thing {String(String),.Number(u64)}

sturdy burrow
#

@sharp marten look above

#

Serde will automatically choose the correct enum based on the type

exotic mirage
#

Value, or make your own enum

#
#[derive(Serialize, Deserialize)]
enum MyApiResult {
    MYSTRING(String),
    MYNUMBER(i32),
}

#[derive(Serialize, Deserialize)]
struct MyApiResult: {
    apikey: MyApiResult
}

serde_json::from_str::<MyApiResult>(jsonstring);
pulsar wigeon
sturdy burrow
#

Oh yeah and that