const
const JSON_NULL: int
module
stdlib::json
defined in C:\Users\bye45\.glide\bin/src/stdlib/json.glide
Two-way JSON binding. User structs that implement this trait can
const
const JSON_BOOL: int
const
const JSON_INT: int
const
const JSON_FLOAT: int
const
const JSON_STRING: int
const
const JSON_ARRAY: int
const
const JSON_OBJECT: int
struct
struct JsonValue
struct
struct JsonParser
trait
trait JsonBind
Two-way JSON binding. User structs that implement this trait can flow through the typed handler helpers (json_respond, HttpResponse::ok().json_of(...), the @handler proc macro) without hand-rolling the parse and emit ceremony.
struct Pet {
pub name: string,
pub age: ?int,
}
impl JsonBind for Pet {
fn from_json(v: *JsonValue) -> !Pet {
if v.kind != JSON_OBJECT { return err("expected object"); }
return ok(Pet {
name: v.get_string("name")?,
age: v.opt_int("age"),
});
}
fn to_json(self: *Pet) -> *JsonValue {
let v: *JsonValue = JsonValue::object();
v.obj_set("name", JsonValue::string(self.name));
if self.age.has {
v.obj_set("age", JsonValue::int(self.age.val));
}
return v;
}
}