js_value!() { /* proc-macro */ }Expand description
Create a JsObject object from a simpler DSL that resembles JSON.
let value = js_object!({
// Comments are allowed inside. String literals will always be transformed to `JsString`.
"key": "value",
// Identifiers will be used as keys, like in JavaScript.
alsoKey: 1,
// Expressions surrounded by brackets will be expressed, like in JavaScript.
// Note that in this case, the unit value is represented by `null`.
[1 + 2]: (),
}, context);
assert_eq!(
JsValue::from(value).display().to_string(),
"{\n 3: null,\n key: \"value\",\n alsoKey: 1\n}"
);The js_value! macro creates a JsValue instance based on a JSON-like DSL.