{"id":15436569,"url":"https://github.com/erosb/json-skema","last_synced_at":"2025-04-05T08:04:18.254Z","repository":{"id":43102942,"uuid":"314666360","full_name":"erosb/json-sKema","owner":"erosb","description":"JSON Schema Validator for the JVM, implements draft2020-12","archived":false,"fork":false,"pushed_at":"2025-03-03T18:32:03.000Z","size":819,"stargazers_count":62,"open_issues_count":19,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T07:06:41.894Z","etag":null,"topics":["json-schema","json-schema-validator"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erosb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-11-20T20:51:00.000Z","updated_at":"2025-03-26T19:04:35.000Z","dependencies_parsed_at":"2024-04-04T05:24:08.084Z","dependency_job_id":"f8f761fe-7389-4103-976e-4ef6019c5053","html_url":"https://github.com/erosb/json-sKema","commit_stats":{"total_commits":389,"total_committers":8,"mean_commits":48.625,"dds":0.390745501285347,"last_synced_commit":"00e6018c715c91accad451c137ce1cabdc5fade5"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erosb%2Fjson-sKema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erosb%2Fjson-sKema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erosb%2Fjson-sKema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erosb%2Fjson-sKema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erosb","download_url":"https://codeload.github.com/erosb/json-sKema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305932,"owners_count":20917208,"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":["json-schema","json-schema-validator"],"created_at":"2024-10-01T18:51:32.885Z","updated_at":"2025-04-05T08:04:18.223Z","avatar_url":"https://github.com/erosb.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-sKema\n\n_json-sKema is a [Json Schema](https://json-schema.org/) validator library for the Java Virtual Machine. It implements the [draft 2020-12](https://json-schema.org/draft/2020-12/json-schema-validation.html) specification._\n\nAre you new to JSON Schema? Get started with [Understanding JSON Schema](https://json-schema.org/understanding-json-schema/)!\n\n\u003c!-- TOC --\u003e\n* [json-sKema](#json-skema)\n  * [Installation](#installation)\n    * [Maven](#maven)\n    * [Gradle](#gradle)\n  * [Usage](#usage)\n    * [Hello-world](#hello-world)\n    * [Loading a schema file from URL](#loading-a-schema-file-from-url)\n    * [Pre-registering schemas by URI before schema loading](#pre-registering-schemas-by-uri-before-schema-loading)\n    * [Validating in Read or Write context](#validating-in-read-or-write-context)\n    * [SchemaBuilder for dynamic (programmatic) schema construction](#schemabuilder-for-dynamic-programmatic-schema-construction)\n  * [Compatibility notes](#compatibility-notes)\n    * [`\"format\"` support](#format-support)\n    * [Support for older JSON Schema drafts](#support-for-older-json-schema-drafts)\n  * [Contribution guideline](#contribution-guideline)\n    * [Building the project:](#building-the-project)\n    * [Building the project and running the official test suite:](#building-the-project-and-running-the-official-test-suite)\n    * [Building the project without running the official test suite:](#building-the-project-without-running-the-official-test-suite)\n\u003c!-- TOC --\u003e\n\n## Installation\n\n### Maven\n\nAdd the following dependency to the `\u003cdependencies\u003e` section of your project:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.erosb\u003c/groupId\u003e\n    \u003cartifactId\u003ejson-sKema\u003c/artifactId\u003e\n    \u003cversion\u003e0.20.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n```groovy\ndependencies {\n    implementation(\"com.github.erosb:json-sKema:0.20.0\")\n}\n```\n\n## Usage\n\n### Hello-world\n\n[Complete source](https://github.com/erosb/json-sKema-examples/blob/master/src/main/java/com/github/erosb/jsonsKema/examples/HelloWorld.java)\n\n```java\n// parse the schema JSON as string\nJsonValue schemaJson = new JsonParser(\"\"\"\n{\n\t\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"age\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"minimum\": 0\n\t\t},\n\t\t\"name\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"email\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"format\": \"email\"\n\t\t}\n\t}\n}\n\"\"\").parse();\n// map the raw json to a reusable Schema instance\nSchema schema = new SchemaLoader(schemaJson).load();\n\n// create a validator instance for each validation (one-time use object)\nValidator validator = Validator.create(schema, new ValidatorConfig(FormatValidationPolicy.ALWAYS));\n\n// parse the input instance to validate against the schema\nJsonValue instance = new JsonParser(\"\"\"\n{\n\t\"age\": -5,\n\t\"name\": null,\n\t\"email\": \"invalid\"\n}\n\"\"\").parse();\n\n// run the validation\nValidationFailure failure = validator.validate(instance);\n\n// print the validation failures (if any)\nSystem.out.println(failure);\n```\n\n### Loading a schema file from URL\n\n```java\n// HTTP(s) protocol is also supported\nSchema schema = SchemaLoader.forURL(\"classpath:///path/to/your/schema.json\").load();\n\n// create a validator instance for each validation (one-time use object) \nValidator validator = Validator.forSchema(schema);\n// ...\n```\n\n### Pre-registering schemas by URI before schema loading\n\n[Complete source](https://github.com/erosb/json-sKema-examples/blob/master/src/main/java/com/github/erosb/jsonsKema/examples/PreRegisteredSchemas.java)\n\n```java\n// Creating a SchemaLoader config with a pre-registered schema by URI\nSchemaLoaderConfig config = createDefaultConfig(Map.of(\n\t\t\t// When the loader sees this URI,\n\t\t\tnew URI(\"urn:uuid:d652a438-9897-4160-959c-bbdb690c3e0d\"),\n\n\t\t\t// then it will resolve it to this schema json\n\t\t\t\"\"\"\n\t\t\t{\n\t\t\t\t\"$defs\": {\n\t\t\t\t\t\"ItemType\": {\n\t\t\t\t\t\t\"type\": \"integer\",\n\t\t\t\t\t\t\"minimum\": 0\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\"\"\"\n\t));\n// parsing the schema json, with a $ref to the above pre-configured URI\nJsonValue schemaJson = new JsonParser(\"\"\"\n\t\t{\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"$ref\": \"urn:uuid:d652a438-9897-4160-959c-bbdb690c3e0d#/$defs/ItemType\"\n\t\t\t}\n\t\t}\n\t\t\"\"\").parse();\n// loading the schema json into a Schema object\nSchema schema = new SchemaLoader(schemaJson, config).load();\n\n// running the validation\nValidationFailure result = Validator.forSchema(schema).validate(new JsonParser(\"[null]\").parse());\nSystem.out.println(result.toJSON());\n```\n\n### Validating in Read or Write context\n\n[Complete source](https://github.com/erosb/json-sKema-examples/blob/master/src/main/java/com/github/erosb/jsonsKema/examples/ReadWriteContextValidation.java)\n\nIf you want to take advantage of the [`\"readOnly\"` and `\"writeOnly\"`](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.4)\nkeywords of json schema, you can tell the `Validator` instance  if the validation happens in read or write context:\n\n```java\nJsonValue schemaJson = new JsonParser(\"\"\"\n{\n    \"type\": \"object\",\n    \"properties\": {\n        \"id\": {\n            \"readOnly\": true,\n            \"type\": \"number\"\n        },\n        \"name\": {\n            \"type\": \"string\"\n        },\n        \"password\": {\n            \"type\": \"string\",\n            \"writeOnly\": true\n        }\n    }\n}\n\"\"\").parse();\n// map the raw json to a reusable Schema instance\nSchema schema = new SchemaLoader(schemaJson).load();\n\n// creating write-context validator, it will report validation failures\n// for read-only properties that are included in the instance\nvar writeContextValidator = Validator.create(schema, ValidatorConfig.builder()\n        .readWriteContext(ReadWriteContext.WRITE)\n        .build()\n);\n\n// creating the json document which will be validated (first in write context, then in read context)\nJsonValue instance = new JsonParser(\"\"\"\n        {\n            \"id\": 1,\n            \"name\": \"John Doe\",\n            \"password\": \"v3ry_s3cur3\"\n        }\n        \"\"\").parse();\nvar writeContextFailure = writeContextValidator.validate(instance);\n\n// prints failure because the read-only property \"id\" is present in write context\nSystem.out.println(writeContextFailure);\n\n// creating read-context validator, it will report validation failures\n// for write-only properties that are included in the instance\nvar readContextValidator = Validator.create(schema, ValidatorConfig.builder()\n        .readWriteContext(ReadWriteContext.READ)\n        .build()\n);\n\nvar readContextFailure = readContextValidator.validate(instance);\n\n// prints failure because the write-only property \"password\" is present in read context\nSystem.out.println(readContextFailure);\n```\n\n### SchemaBuilder for dynamic (programmatic) schema construction\n\nThe library allows dynamic schema construction via its `SchemaBuilder` class. This is useful in cases when, instead of working with\nstatic schemas or externally fed JSON Schemas, the application needs to create a schema instance at run-time, dynamically. This can\nbe done with a fluent API, demonstrated below:\n\n[Complete source](https://github.com/erosb/json-sKema-examples/blob/master/src/main/java/com/github/erosb/jsonsKema/examples/SchemaBuilderDemo.java)\n\n```java\nimport static com.github.erosb.jsonsKema.SchemaBuilder.*;\n//...\ntypeObject()\n    .property(\"myString\", typeString()\n        .minLength(2)\n        .maxLength(50)\n        .pattern(\"^[a-zA-Z ]*$\")\n    ).property(\"myInteger\", typeInteger()\n        .minimum(10)\n        .maximum(20)\n        .multipleOf(4)\n    ).property(\"myObject\", typeObject()\n        .additionalProperties(falseSchema())\n        .patternProperties(Map.of(\n            \"^[A-Z]{2}$\", allOf(\n                typeArray().items(typeNumber())\n                    .prefixItems(List.of(typeBoolean(), typeBoolean())),\n                typeArray().minContains(3, constSchema(new JsonNumber(1.5)))\n            )\n        ))\n    )\n```\n\n## Compatibility notes\n\nThe library implements the JSON Schema draft 2020-12 core and validation specifications, with the following notes:\n * `$dynamicAnchor` and `$dynamicRef` support is partially implemented\n\n### `\"format\"` support\n\nThe library currently has built-in support for the following `\"format\"` values defined in the specification:\n\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\"format\"\u003c/td\u003e\n            \u003ctd\u003eSupported?\u003c/td\u003e\n            \u003ctd\u003eNotes\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n\u003ctbody\u003e\n    \u003ctr\u003e\n        \u003ctd\u003edate\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003edate-time\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003eNon-UTC values with leap seconds not supported\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003etime\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003eduration\u003c/td\u003e\n        \u003ctd\u003ePartially\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003eemail\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003eIPV6 domain parts not supported\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003euri\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003eipv4\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003eipv6\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003euuid\u003c/td\u003e\n        \u003ctd\u003eYes\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\nThe following formats are NOT supported: hostname, idn-email, idn-hostname, iri, iri-reference, json-pointer, regex, relative-json-pointer, uri-reference, uri-template .\n\n\n### Support for older JSON Schema drafts\n\nThis project is the successor of [everit-org/json-schema](https://github.com/everit-org/json-schema). If you want to use draft-04, draft-06 or draft-07 versions of JSON Schema, then you can use the everit library.\n\n\n## Contribution guideline\n\nLocal environment setup:\n\n_Prerequisite: JDK and Maven installed_\n\n```\ngit clone https://github.com/erosb/json-sKema.git\ncd json-sKema\ngit submodule init\ngit submodule update\n```\n\n### Building the project:\n\n`mvn clean package`\n\n### Building the project and running the official test suite:\n\nTest annotated with `@Tag(\"acceptance\")` require the test suite to be pulled using:\n\n`git submodule update --init --recursive`\n\nThen run the tests:\n\n`mvn clean verify`\n\n### Building the project without running the official test suite:\n`mvn clean package -Dgroups='!acceptance'`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferosb%2Fjson-skema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferosb%2Fjson-skema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferosb%2Fjson-skema/lists"}