[]
(https://travis-ci.org/tomjakubowski/json_macros)
Construct JSON objects in Rust from JSON-like literals.
Add to your Cargo.toml
:
toml
[dependencies.json_macros]
git = "https://github.com/tomjakubowski/json_macros"
Or, from the registry: ```toml [dependencies]
json_macros = "~0.0.2" ```
You'll also need to link with the serialize
crate, where the Rust standard
library JSON types live.
```rust
extern crate serialize;
pub fn main() { let x = 123i32; println!("{}", json!({ // object literal "foo": "foooooo", // string literal keys and values "bar": [true, null, 123, 123.4], // array, boolean, null, numeric literals "quux": { // nest as deeply as you like "a": [1, 2, 3, 4], "b": { "a": null }, "c": false }, "waldo": (192 - x) // wrap in parens to splice ToJson expressions directly }).toprettystr()); } ```
()
, as in json!({ "a": (-1234i32) })
.