{"id":22750051,"url":"https://github.com/pwall567/json-kotlin-schema","last_synced_at":"2025-04-04T18:04:37.452Z","repository":{"id":48663732,"uuid":"281935386","full_name":"pwall567/json-kotlin-schema","owner":"pwall567","description":"Kotlin implementation of JSON Schema (Draft 07)","archived":false,"fork":false,"pushed_at":"2025-03-13T21:25:19.000Z","size":302,"stargazers_count":94,"open_issues_count":9,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T17:02:33.882Z","etag":null,"topics":["json-schema","kotlin"],"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/pwall567.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-07-23T11:40:36.000Z","updated_at":"2025-03-13T21:25:02.000Z","dependencies_parsed_at":"2022-08-23T00:40:59.425Z","dependency_job_id":"9642d3e7-4d3e-49d2-b8ba-5d51286a8fb2","html_url":"https://github.com/pwall567/json-kotlin-schema","commit_stats":null,"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fjson-kotlin-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fjson-kotlin-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fjson-kotlin-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fjson-kotlin-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwall567","download_url":"https://codeload.github.com/pwall567/json-kotlin-schema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226213,"owners_count":20904465,"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","kotlin"],"created_at":"2024-12-11T04:11:49.779Z","updated_at":"2025-04-04T18:04:37.434Z","avatar_url":"https://github.com/pwall567.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-kotlin-schema\n\n[![Build Status](https://github.com/pwall567/json-kotlin-schema/actions/workflows/build.yml/badge.svg)](https://github.com/pwall567/json-kotlin-schema/actions/workflows/build.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Kotlin](https://img.shields.io/static/v1?label=Kotlin\u0026message=v2.0.21\u0026color=7f52ff\u0026logo=kotlin\u0026logoColor=7f52ff)](https://github.com/JetBrains/kotlin/releases/tag/v2.0.21)\n[![Maven Central](https://img.shields.io/maven-central/v/net.pwall.json/json-kotlin-schema?label=Maven%20Central)](https://central.sonatype.com/artifact/net.pwall.json/json-kotlin-schema)\n\nKotlin implementation of JSON Schema (Draft-07)\n\n**NOTE:** \u0026ndash; from version 0.49, the underlying JSON and YAML libraries have been switched from\n[`jsonutil`](https://github.com/pwall567/jsonutil) and [`yaml-simple`](https://github.com/pwall567/yaml-simple) to\n[`kjson-core`](https://github.com/pwall567/kjson-core) and [`kjson-yaml`](https://github.com/pwall567/kjson-yaml).\nThe change should be transparent to most users.\n\n## Quick Start\n\nGiven the following schema file (Taken from the [Wikipedia article on JSON](https://en.wikipedia.org/wiki/JSON)):\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft/2019-09/schema\",\n  \"$id\": \"http://pwall.net/test\",\n  \"title\": \"Product\",\n  \"type\": \"object\",\n  \"required\": [\"id\", \"name\", \"price\"],\n  \"properties\": {\n    \"id\": {\n      \"type\": \"number\",\n      \"description\": \"Product identifier\"\n    },\n    \"name\": {\n      \"type\": \"string\",\n      \"description\": \"Name of the product\"\n    },\n    \"price\": {\n      \"type\": \"number\",\n      \"minimum\": 0\n    },\n    \"tags\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"stock\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"warehouse\": {\n          \"type\": \"number\"\n        },\n        \"retail\": {\n          \"type\": \"number\"\n        }\n      }\n    }\n  }\n}\n```\nand this JSON (from the same article):\n```json\n{\n  \"id\": 1,\n  \"name\": \"Foo\",\n  \"price\": 123,\n  \"tags\": [\n    \"Bar\",\n    \"Eek\"\n  ],\n  \"stock\": {\n    \"warehouse\": 300,\n    \"retail\": 20\n  }\n}\n```\nthe following code will validate that the JSON matches the schema:\n```kotlin\n    val schema = JSONSchema.parseFile(\"/path/to/example.schema.json\")\n    val json = File(\"/path/to/example.json\").readText()\n    require(schema.validate(json))\n```\n\nTo see the detail of any errors found during validation:\n```kotlin\n    val schema = JSONSchema.parseFile(\"/path/to/example.schema.json\")\n    val json = File(\"/path/to/example.json\").readText()\n    val output = schema.validateBasic(json)\n    output.errors?.forEach {\n        println(\"${it.error} - ${it.instanceLocation}\")\n    }\n```\n\nThe format of the error object produced by the `validateBasic()` function closely follows the\n[Basic output](https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.10.4.2) specification.\n\nIt is also possible to read a schema from a string in memory:\n```kotlin\n    val str = File(\"/path/to/example.schema.json\").readText()\n    val schema = JSONSchema.parse(str)\n```\nAn optional second parameter on the `parse()` function takes a URI, which will be used to construct the location in\nerror objects.\n\n## YAML\n\nWhile it may seem counter-intuitive to use a language other than JSON to express JSON Schema, YAML is a lot easier to\nwork with, particularly when multi-line descriptions are required.\nThis library functions equally well with schema representations in JSON or YAML.\n\nFor example, the above schema looks like this in YAML:\n```yaml\n$schema: http://json-schema.org/draft/2019-09/schema\n$id: http://pwall.net/test\ntitle: Product\ntype: object\nrequired:\n- id\n- name\n- price\nproperties:\n  id:\n    type: number\n    description: Product identifier\n  name:\n    type: string\n    description: Name of the product\n  price:\n    type: number\n    minimum: 0\n  tags:\n    type: array\n    items:\n      type: string\n  stock:\n    type: object\n    properties:\n      warehouse:\n        type: number\n      retail:\n        type: number\n```\n\nTo use this schema, simply specify a schema file with an extension of `.yaml` or `.yml` to the schema parser:\n```kotlin\n    val schema = JSONSchema.parseFile(\"/path/to/example.schema.yaml\")\n```\n\nThe YAML library used is [this one](https://github.com/pwall567/kjson-yaml).\n\n## References\n\nAt many points in a JSON Schema, the `$ref` construct allows a reference to schema information defined elsewhere.\nThe reference takes the form of a URL, which may be internal to the current schema document (reference starts with\na `#` character) or external - the reference points to a different document.\n\nInternal references are resolved relative to the root of the schema document in which they appear, for example:\n```json\n{\n  \"$ref\": \"#/$defs/Account\"\n}\n```\nThis points to a schema named `Account` in the `$defs` section of the current schema document.\n\nAn external reference may be relative (in which case the URL will be resolved relative to the location of the document\nin which the reference appears) or absolute.\nThe external reference may include a fragment (a JSON Pointer starting with `#`); if it does not the reference is taken\nas pointing to the root of the document.\nFor example:\n```json\n{\n  \"$ref\": \"common.schema.json#/$defs/Address\"\n}\n```\nThis will look for a sibling (URL or file) to the current document and attempt to locate the `Address` schema in the\n`$defs` section of that document.\n\n## `examples` and `default`\n\nThe JSON Schema specification says, of `examples` and `default`: \u0026ldquo;It is RECOMMENDED that these values be valid\nagainst the associated schema.\u0026rdquo;\nThe schema parser allows for the optional validation of `examples` and `default` entries; it requires the creation of a\nnew Parser instance, and the setting of option flags:\n```kotlin\n    val parser = Parser()\n    parser.options.validateExamples = true // to cause \"examples\" (and \"example\") entries to be validated\n    parser.options.validateDefault = true  // to cause \"default\" entries to be validated\n    parser.parseFile(filename)\n    if (parser.examplesValidationErrors.isNotEmpty()) {\n        // parser.examplesValidationErrors is a List of BasicOutput objects, one for each error found in examples\n    }\n    if (parser.defaultValidationErrors.isNotEmpty()) {\n        // parser.examplesValidationErrors is a List of BasicOutput objects, one for each error found in default entries\n    }\n```\n\n## Implemented Subset\n\nThis implementation does not implement the full JSON Schema specification.\nIt covers much of [Draft 07](https://json-schema.org/specification-links.html#draft-7) and a few features from\n[Draft 2019-09](https://json-schema.org/specification-links.html#draft-2019-09).\n\nThe currently implemented subset includes:\n\n### Core\n\n- `$schema`\n- `$id`\n- `$ref` (with some reservations)\n- `$defs`\n- `$comment`\n- `title`\n- `description`\n- `examples`\n\n### Structure\n\n- `properties`\n- `patternProperties`\n- `additionalProperties`\n- `propertyNames`\n- `items`\n- `additionalItems`\n- `allOf`\n- `anyOf`\n- `oneOf`\n- `if`\n- `then`\n- `else`\n- `default`\n\n### Validation\n\n- `type` (`null`, `boolean`, `object`, `array`, `number`, `string`, `integer`)\n- `format` (`date-time`, `date`, `time`, `duration`, `email`, `hostname`, `uri`, `uri-reference`, `uri-template`,\n`uuid`, `ipv4`, `ipv6`, `json-pointer`, `relative-json-pointer`, `regex`)\n- `enum`\n- `const`\n- `multipleOf`\n- `maximum`\n- `exclusiveMaximum`\n- `minimum`\n- `exclusiveMinimum`\n- `minProperties`\n- `maxProperties`\n- `minItems`\n- `maxItems`\n- `uniqueItems`\n- `maxLength`\n- `minLength`\n- `pattern`\n- `required`\n- `contains`\n- `maxContains`\n- `minContains`\n\n## Not Currently Implemented\n\n- `$recursiveRef`\n- `$recursiveAnchor`\n- `$anchor`\n- `$vocabulary`\n- `unevaluatedProperties`\n- `unevaluatedItems`\n- `dependentcies`\n- `dependentSchemas`\n- `dependentRequired`\n- `contentEncoding`\n- `contentMediaType`\n- `contentSchema`\n- `deprecated`\n- `readOnly`\n- `writeOnly`\n- `format` (`idn-email`, `idn-hostname`, `iri`, `iri-reference`)\n\nMore documentation to follow.\n\n## Dependency Specification\n\nThe latest version of the library is 0.56, and it may be obtained from the Maven Central repository.\n\n### Maven\n```xml\n    \u003cdependency\u003e\n      \u003cgroupId\u003enet.pwall.json\u003c/groupId\u003e\n      \u003cartifactId\u003ejson-kotlin-schema\u003c/artifactId\u003e\n      \u003cversion\u003e0.56\u003c/version\u003e\n    \u003c/dependency\u003e\n```\n### Gradle\n```groovy\n    implementation 'net.pwall.json:json-kotlin-schema:0.56'\n```\n### Gradle (kts)\n```kotlin\n    implementation(\"net.pwall.json:json-kotlin-schema:0.56\")\n```\n\nPeter Wall\n\n2025-02-09\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Fjson-kotlin-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwall567%2Fjson-kotlin-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Fjson-kotlin-schema/lists"}