json_typegen_cli 0.1.0

Command line utility for generating Rust types from JSON samples
json_typegen_cli-0.1.0 is not a library.

CLI for JSON code generation for Rust

Note: The main intended interface for this code generation is a procedural macro. See its docs for details.


cargo install json_typegen_cli
# installed binary is called json_typegen

Due to the fact that this tool uses rustfmt to make code look reasonable, compilation takes a while. If you are impatient, you can use the web interface in the meantime.


To generate the type Point in point.rs from a local sample, run:

json_typegen json_samples/point.json -o src/point.rs -n Point

Or for an online sample, run:

json_typegen 'http://vestera.as/json_typegen/examples/point.json' -o src/point.rs -n Point

The generated code assumes the availability of serde and serde_derive, so make sure your Cargo.toml contains something like:

serde = "0.9"
serde_derive = "0.9"
# Not required, but you probably also want:
serde_json = "0.9"

And your crate root (i.e. main.rs) should contain at least:

extern crate serde;
extern crate serde_derive;
// Again, not required, but you probably also want:
extern crate serde_json;