#json #schema #code #generator

jsonschema_code_generator

Crate for generating rust types from JSON schemas

6 releases (2 stable)

2.0.0 Jun 29, 2021
1.0.0 Jun 29, 2021
0.2.1 Jun 28, 2021
0.1.1 May 21, 2021

#983 in Procedural macros

Download history 7/week @ 2022-03-09 28/week @ 2022-03-16 18/week @ 2022-03-23 7/week @ 2022-03-30 8/week @ 2022-04-06 34/week @ 2022-04-13 18/week @ 2022-04-20 48/week @ 2022-04-27 30/week @ 2022-05-04 97/week @ 2022-05-11 32/week @ 2022-05-18 31/week @ 2022-05-25 56/week @ 2022-06-01 18/week @ 2022-06-08 10/week @ 2022-06-15 19/week @ 2022-06-22

104 downloads per month
Used in webthings-gateway-ipc-types

MPL-2.0 license

79KB
2K SLoC

jsonschema_code_generator

Build Status Latest Version Docs

This Rust crate allows you to generate Rust types from JSON Schemas.

It attaches serde_json attributes to the structs for json serialization/deserialization.

Example

use jsonschema_code_generator::generate;
use std::path::Path;

fn main() {
    let rust_code = generate(&Path::new("schemas/draft-04.json"));
    println!("{}", rust_code);
}

Todo

  • Add support for draft 4 schemas
  • Resolve definitions across files
  • Resolve struct name collisions
  • Add macro
  • Merge anyOf and allOf definitions to a single type
  • Add support for draft 7 schemas
  • Add support for draft 2019-09 schemas
  • Add support for draft 2020-12 schemas

Dependencies

~0.7–1.4MB
~32K SLoC