| Crates.io | json-schema-dsl |
| lib.rs | json-schema-dsl |
| version | 0.2.2 |
| created_at | 2024-08-12 15:09:31.331142+00 |
| updated_at | 2024-12-14 01:22:04.527884+00 |
| description | A simple DSL to write JSON Schema |
| homepage | https://github.com/linux-china/json-schema-dsl |
| repository | https://github.com/linux-china/json-schema-dsl |
| max_upload_size | |
| id | 1334595 |
| size | 381,688 |
A simple DSL to generate JSON Schema with one-liner style.
Make JSON Schema concise:

AI friendly: Function calling, Structured Output with simple DSL:

Schema friendly for CSV, Excel, Text2SQL:

CLI: cargo install json-schema-dsl
$ json-schema-dsl "User{ id: int, name: string, email: Email}"
Output as following:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "User",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
}
},
"required": [
"id",
"name",
"email"
]
}
Rust library: cargo add json-schema-dsl serde_json
fn main() {
let struct_text = "User {id: int, name: string, email: Email}";
let json_schema = json_schema_dsl::to_json_schema(struct_text).unwrap();
println!("{}", serde_json::to_string_pretty(&json_schema).unwrap());
}

User { id: int, name: string, birth_date: Date, email?: Email, tags: List<string>}
ObjectName { field: type }.field?: typeJSON Schema basic types:
string: aliases: varchar, Text, String, bytes or bytea(base64)integer: aliases: int, bigint, long, serial, bigserial,int32, int64, int96, int128number: aliases: float, double, real, decimalboolean: aliases: boolExtra types are for semantic meaning, and they are all string type.
Path: /path/to/fileS3Path: s3://bucket/keyUlid or ULIDColor: #F7F8FAIsbn or ISBN: 978-3-16-148410-0SemVer: 1.2.3PhoneNumber: +1-202-555-0192CreditCard: 4111 1111 1111 1111Currency: USD, CNYLanguage: en, zh-CNLocale: en-US, zh-CNMimeType: application/jsonBase64: base64 encoded stringarray type is alike List<T>, and T is a basic type or format name.
List: aliases: listArray: aliases: arraySet(uniqueItems): aliases: setDeclare object type: field: ObjectName {field: type}.
Attention: ObjectName should start with Capital Character.
JSON Schema formats, and name should start with a capital letter:
DateTimeDatetimeTimestampIntervalDurationEmailHostnameDomainnameIpv4Ipv6UriUuid or UUIDJson or JSON: JSON textXml or XML: XML textage: int(18,), age: int(,150) or age: int(1,18)nick: string(6,32), varchar(32)list<string>(2), list<float>(1536)income: [int, string]enum('a', 'b', 'c') or enum(1, 2, 3)regex('^[a-z]+$')field: type1|type2, no space between types{field: type, ...}, ellipsis before }.