Note: For Rust types there is also a procedural macro interface to this code, which uses the same underlying algorithm and code generation. See the repository for details.
```sh cargo install jsontypegencli
```
To generate the Rust type Point
in point.rs
from a local sample, run:
sh
json_typegen json_samples/point.json -o src/point.rs -n 'pub Point'
Note: The output file (e.g. src/point.rs
) will be overwritten if it exists.
For an online sample, run:
sh
json_typegen 'http://vestera.as/json_typegen/examples/point.json' -o src/point.rs -n 'pub Point'
The generated code assumes the availability of serde
and serde_derive
, so
make sure your Cargo.toml
contains something like:
```toml [dependencies] serde = "1.0" serde_derive = "1.0"
serde_json = "1.0" ```
For help with the CLI itself run json_typegen -h
. To configure visibility and
other options see the general configuration documentation.
The CLI currently has rudimentary support for Kotlin, TypeScript and JSON Schema. Contributions for these and additions of others are welcome.