json_typegen_cli

Crates.iojson_typegen_cli
lib.rsjson_typegen_cli
version0.7.0
sourcesrc
created_at2017-04-21 08:25:35.338439
updated_at2021-09-16 16:19:56.409508
descriptionCommand line utility for generating Rust types from JSON samples
homepagehttps://github.com/evestera/json_typegen
repositoryhttps://github.com/evestera/json_typegen
max_upload_size
id11410
size48,964
Erik Vesteraas (evestera)

documentation

https://docs.rs/json_typegen_cli

README

CLI for generation of type definitions for Rust, Kotlin, TypeScript and JSON Schema from JSON

Note: There is also a web interface, and 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 and typegen.vestera.as for the web interface.

Installation

Install with cargo:

cargo install json_typegen_cli
# installed binary is called json_typegen
# make sure ~/.cargo/bin is on your PATH

Or download precompiled binaries from the GitHub releases page.

Usage

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

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

Note: The output file (e.g. src/point.rs) will be overwritten if it exists.

For an online sample, run:

json_typegen 'https://typegen.vestera.as/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:

[dependencies]
serde = "1.0"
serde_derive = "1.0"
# Not required for the types themselves, but you probably also want:
serde_json = "1.0"

Options and configurations

For help with the CLI itself run json_typegen -h. To configure visibility and other options see the general configuration documentation.

Other languages

You can output code for other languages with the --output-mode option. From --help:

    -O, --output-mode <output-mode>    What to output. [possible values: rust, typescript, typescript/typealias, kotlin,
                                       kotlin/jackson, kotlin/kotlinx, json_schema, shape]
Commit count: 256

cargo fmt