#json #schema #zod #compiler

bin+lib rust-ts-json-compiler

ts-zod compiller to json

2 unstable releases

0.2.0 Nov 20, 2023
0.1.0 Oct 24, 2023

#2928 in Database interfaces

MIT license

22KB
631 lines

Rust zod compiler

Compiles zod schema to valid json payload.

Usage


pub fn main() {
    let zod_schema = "
    z.object({
        products: z.array(
          z.object({
            productId: z.number().int(),
            amount: z.number().int(),
            price: z.number()
          })
        ),
        cityId: z.number().int(),
        comment: z.string()
    })
    ";

    let json_schema = rust_ts_json_compiler::to_json(zod_schema);

    /* 
    {
        "products": [
            {
                "productId": 1,
                "amount": 1,
                "price": 5
            }
        ],
        "cityId": 1,
        "comment": "string"
    }
    */
    println!("{}", json_schema);
}

Dependencies

~0.4–1MB
~20K SLoC