{"id":18558998,"url":"https://github.com/linux-china/json-schema-dsl","last_synced_at":"2025-04-10T01:33:08.894Z","repository":{"id":252791043,"uuid":"841518063","full_name":"linux-china/json-schema-dsl","owner":"linux-china","description":"JSON Schema DSL","archived":false,"fork":false,"pushed_at":"2024-12-14T07:29:39.000Z","size":386,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T02:51:10.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linux-china.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-12T15:07:17.000Z","updated_at":"2024-12-14T07:29:42.000Z","dependencies_parsed_at":"2024-08-12T15:17:08.261Z","dependency_job_id":"fb6f9470-9dee-4336-8122-e54bd493a5e7","html_url":"https://github.com/linux-china/json-schema-dsl","commit_stats":null,"previous_names":["linux-china/json-schema-dsl"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fjson-schema-dsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fjson-schema-dsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fjson-schema-dsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fjson-schema-dsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linux-china","download_url":"https://codeload.github.com/linux-china/json-schema-dsl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248140798,"owners_count":21054353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:41:48.930Z","updated_at":"2025-04-10T01:33:03.878Z","avatar_url":"https://github.com/linux-china.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSON Schema DSL\n==================\n\nA simple DSL to generate JSON Schema with one-liner style.\n\n# Why JSON Schema DSL?\n\n1. Make JSON Schema concise:\n   ![JSON Schema DSL CLI](docs/images/json-schema-dsl-cli.png)\n\n2. AI friendly: Function calling, Structured Output with simple DSL:\n   ![JSON Schema DSL CLI](docs/images/ai-structured-output.png)\n\n3. Schema friendly for CSV, Excel, Text2SQL:\n   ![JSON Schema DSL CLI](docs/images/json-schema-text2sql.png)\n\n# Get Started\n\nCLI: `cargo install json-schema-dsl`\n\n```shell\n$ json-schema-dsl \"User{ id: int, name: string, email: Email}\"\n```\n\nOutput as following:\n\n```json\n{\n  \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n  \"title\": \"User\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"id\": {\n      \"type\": \"integer\"\n    },\n    \"name\": {\n      \"type\": \"string\"\n    },\n    \"email\": {\n      \"type\": \"string\",\n      \"format\": \"email\"\n    }\n  },\n  \"required\": [\n    \"id\",\n    \"name\",\n    \"email\"\n  ]\n}\n```\n\nRust library: `cargo add json-schema-dsl serde_json`\n\n```rust\nfn main() {\n    let struct_text = \"User {id: int, name: string, email: Email}\";\n    let json_schema = json_schema_dsl::to_json_schema(struct_text).unwrap();\n    println!(\"{}\", serde_json::to_string_pretty(\u0026json_schema).unwrap());\n}\n```\n\n# Syntax\n\n![JSON Schema DSL](json-schema-dsl.png)\n\n`User { id: int, name: string, birth_date: Date, email?: Email, tags: List\u003cstring\u003e}`\n\n- Object Name: starts with capital character, such as `ObjectName { field: type }`.\n- Field name: starts with lower-case character.\n- Optional field: `field?: type`\n\n### Basic Types\n\nJSON Schema basic types:\n\n- `string`: aliases:  `varchar`, `Text`, `String`, `bytes` or `bytea`(base64)\n- `integer`: aliases: `int`, `bigint`, `long`, `serial`, `bigserial`,`int32`, `int64`, `int96`, `int128`\n- `number`: aliases: `float`, `double`, `real`, `decimal`\n- `boolean`: aliases: `bool`\n\n### array Types\n\narray type is alike `List\u003cT\u003e`, and T is a basic type or format name.\n\n- `List`: aliases: `list`\n- `Array`: aliases: `array`\n- `Set`(uniqueItems): aliases: `set`\n\n### object Type\n\nDeclare object type: `field: ObjectName {field: type}`.\n\n**Attention**: `ObjectName` should start with Capital Character.\n\n### Formats\n\nJSON Schema formats, and name should start with a capital letter:\n\n- `Date`\n- `Time`\n- `Datetime`\n- `Timestamp`\n- `Interval`\n- `Duration`\n- `Email`\n- `Hostname`\n- `Ipv4`\n- `Ipv6`\n- `Uri`\n- `Hostname`\n- `Uuid` or `UUID`\n- `Json` or `JSON`: JSON text\n- `Xml` or `XML`: XML text\n\n### Misc\n\n- range: `age: int(18,)`, `age: int(,150)` or `age: int(1,18)`\n- string length range: `nick: string(6,32)`, `varchar(32)`\n- array items length range: `list\u003cstring\u003e(2)`, `list\u003cfloat\u003e(1536)`\n- tuple: `income: [int, string]`\n- enum: `enum('a', 'b', 'c')` or `enum(1, 2, 3)`\n- regex: `regex('^[a-z]+$')`\n- anyOf: `field: type1|type2`, no space between types\n- additionalProperties: `{field: type, ...}`, ellipsis before `}`.\n\n# References\n\n* JSON Schema: https://json-schema.org/\n* JSON Schema formats: https://json-schema.org/understanding-json-schema/reference/string#built-in-formats\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Fjson-schema-dsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinux-china%2Fjson-schema-dsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Fjson-schema-dsl/lists"}