JSON
JSON format (application/json).
JSON is Stof's closest relative format. The Stof parser accepts JSON field & object syntax (most JSON files can be considered Stof).
Stof, unlike JSON, is not limited to just fields of data, however. Because of this, the JSON format implementation is a lossy export, but captures everything on import.
{
"message": "hello, world",
"person": {
"name": "Bob Smith",
"age": 42
}
}import "./test.json"; // uses "json" format
#[main]
fn main() {
assert_eq(self.message, "hello, world");
assert_eq(self.person.name, "Bob Smith");
assert_eq(self.person.age, 42);
const json = stringify("json", self); // string export (fields only)
assert_eq(json, '{"message":"hello, world","person":{"name":"Bob Smith","age":42}}');
}Last updated
Was this helpful?