{"id":21526767,"url":"https://github.com/dragonwasrobot/json_schema","last_synced_at":"2026-03-08T02:05:02.434Z","repository":{"id":38361554,"uuid":"142361809","full_name":"dragonwasrobot/json_schema","owner":"dragonwasrobot","description":"A library for parsing, inspecting and manipulating JSON Schema documents","archived":false,"fork":false,"pushed_at":"2026-01-26T07:12:47.000Z","size":618,"stargazers_count":10,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-26T21:40:02.590Z","etag":null,"topics":["elixir","elixir-lang","elixir-library","json","json-schema","parser"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/json_schema","language":"Elixir","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/dragonwasrobot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-07-25T22:56:01.000Z","updated_at":"2026-01-26T07:12:50.000Z","dependencies_parsed_at":"2023-02-13T01:16:13.857Z","dependency_job_id":"38f3719a-64ab-4039-983f-f77f3d596167","html_url":"https://github.com/dragonwasrobot/json_schema","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/dragonwasrobot/json_schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonwasrobot%2Fjson_schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonwasrobot%2Fjson_schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonwasrobot%2Fjson_schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonwasrobot%2Fjson_schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dragonwasrobot","download_url":"https://codeload.github.com/dragonwasrobot/json_schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonwasrobot%2Fjson_schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30242404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elixir","elixir-lang","elixir-library","json","json-schema","parser"],"created_at":"2024-11-24T01:46:36.231Z","updated_at":"2026-03-08T02:05:02.414Z","avatar_url":"https://github.com/dragonwasrobot.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Schema\n\n[![Module Version](https://img.shields.io/hexpm/v/json_schema.svg)](https://hex.pm/packages/json_schema)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/json_schema/)\n[![License](https://img.shields.io/hexpm/l/json_schema.svg)](https://github.com/dragonwasrobot/json_schema/blob/master/LICENSE)\n\nA JSON schema parser for inspection and manipulation of JSON Schema Abstract\nSyntax Trees (ASTs). This library is meant as a basis for writing other\nlibraries or tools that need to use JSON schema documents. For example, a JSON\nschema validator that validates a JSON object according to a JSON schema\nspecification, or a code generator that generates a data model and accompanying\nJSON serializers based on the JSON schema specification of an API -- the project\n[JSON Schema to Elm](https://github.com/dragonwasrobot/json-schema-to-elm) is an\nexample of such a tool.\n\n## Installation\n\nAdd `:json_schema` as a dependency in `mix.exs`:\n\n```elixir\ndefp deps do\n  [\n    {:json_schema, \"~\u003e 0.5\"}\n  ]\nend\n```\n\n## Usage\n\n\u003e The words *type* and *subschema* are used interchangeable in the rest of\n\u003e the document.\n\nThe main API entry point is the `JsonSchema` module, which supports parsing a\nlist of JSON schema files into JSON Schema ASTs via `parse_schema_files`, or\nresolving a JSON schema type given an identifier via `resolve_type`.\n\n### Parsing a JSON schema file into an Abstract Syntax Tree\n\nPresuming we have the following two JSON schema files:\n\n```json\n{\n    \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n    \"$id\": \"http://example.com/circle.json\",\n    \"title\": \"Circle\",\n    \"description\": \"Schema for a circle shape\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"center\": {\n            \"$ref\": \"http://example.com/definitions.json#point\"\n        },\n        \"radius\": {\n            \"type\": \"number\"\n        },\n        \"color\": {\n            \"$ref\": \"http://example.com/definitions.json#color\"\n        }\n    },\n    \"required\": [\"center\", \"radius\"]\n}\n```\n\nand\n\n```json\n{\n    \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n    \"title\": \"Definitions\",\n    \"$id\": \"http://example.com/definitions.json\",\n    \"description\": \"Schema for common types\",\n    \"definitions\": {\n        \"color\": {\n            \"$id\": \"#color\",\n            \"type\": \"string\",\n            \"enum\": [ \"red\", \"yellow\", \"green\", \"blue\" ]\n        },\n        \"point\": {\n            \"$id\": \"#point\",\n            \"type\": \"object\",\n            \"properties\": {\n                \"x\": {\n                    \"type\": \"number\"\n                },\n                \"y\": {\n                    \"type\": \"number\"\n                }\n            },\n            \"required\": [ \"x\", \"y\" ]\n        }\n    }\n}\n```\n\nwe can parses the into a JSON schema AST by passing them to\n`JsonSchema.parse_schema_files`. This produces a `SchemaResult` containing a\nschema dictionary, `schema_dict`, and any errors or warnings generated along the\nway.\n\n```elixir\nschema_paths = [\"./path/to/json_schemas/circle.json\",\n                \"./path/to/json_schemas/definitions.json\"\n               ]\nschema_result = JsonSchema.parse_schema_files(schema_paths)\n%JsonSchema.Parser.SchemaResult{\n  errors: [],\n  warnings: [],\n  schema_dict: %{\n    \"http://example.com/circle.json\" =\u003e %JsonSchema.Types.SchemaDefinition{\n      description: \"Schema for a circle shape\",\n      file_path: \"/path/to/json-schemas/circle.json\",\n      id: URI.parse(\"http://example.com/circle.json\"),\n      title: \"Circle\",\n      types: %{\n        \"#\" =\u003e %JsonSchema.Types.ObjectType{\n          additional_properties: nil,\n          description: \"Schema for a circle shape\",\n          name: \"Circle\",\n          path: URI.parse(\"#\"),\n          pattern_properties: %{},\n          properties: %{\n            \"center\" =\u003e URI.parse(\"#/properties/center\"),\n            \"color\" =\u003e URI.parse(\"#/properties/color\"),\n            \"radius\" =\u003e URI.parse(\"#/properties/radius\")\n          },\n          required: [\"center\", \"radius\"]\n        },\n        \"#/properties/center\" =\u003e %JsonSchema.Types.TypeReference{\n          name: \"center\",\n          path: URI.parse(\"http://example.com/definitions.json#point\")\n        },\n        \"#/properties/color\" =\u003e %JsonSchema.Types.TypeReference{\n          name: \"color\",\n          path: URI.parse(\"http://example.com/definitions.json#color\")\n        },\n        \"#/properties/radius\" =\u003e %JsonSchema.Types.PrimitiveType{\n          description: nil,\n          name: \"radius\",\n          path: URI.parse(\"#/properties/radius),\n          type: :number\n        },\n        \"http://example.com/circle.json#\" =\u003e %JsonSchema.Types.ObjectType{\n          additional_properties: nil,\n          description: \"Schema for a circle shape\",\n          name: \"Circle\",\n          path: URI.parse(\"#\"),\n          pattern_properties: %{},\n          properties: %{\n            \"center\" =\u003e URI.parse(\"#/properties/center\"),\n            \"color\" =\u003e URI.parse(\"#/properties/color\"),\n            \"radius\" =\u003e URI.parse(\"#/properties/radius\")\n          },\n          required: [\"center\", \"radius\"]\n        }\n      }\n    },\n    \"http://example.com/definitions.json\" =\u003e %JsonSchema.Types.SchemaDefinition{\n      description: \"Schema for common types\",\n      file_path: \"/path/to/json-schemas/definitions.json\",\n      id: URI.parse(\"http://example.com/definitions.json\"),\n      title: \"Definitions\",\n      types: %{\n        \"#/definitions/color\" =\u003e %JsonSchema.Types.EnumType{\n          description: nil,\n          name: \"color\",\n          path: URI.parse(\"#/definitions/color\"),\n          type: :string,\n          values: [\"red\", \"yellow\", \"green\", \"blue\"]\n        },\n        \"#/definitions/point\" =\u003e %JsonSchema.Types.ObjectType{\n          additional_properties: nil,\n          description: nil,\n          name: \"point\",\n          path: URI.parse(\"#/definitions/point\"),\n          pattern_properties: %{},\n          properties: %{\n            \"x\" =\u003e URI.parse(\"#/definitions/point/properties/x\"),\n            \"y\" =\u003e URI.parse(\"#/definitions/point/properties/y\")\n          },\n          required: [\"x\", \"y\"]\n        },\n        \"#/definitions/point/properties/x\" =\u003e %JsonSchema.Types.PrimitiveType{\n          description: nil,\n          name: \"x\",\n          path: URI.parse(\"/definitions/point/properties/x\"),\n          type: :number\n        },\n        \"#/definitions/point/properties/y\" =\u003e %JsonSchema.Types.PrimitiveType{\n          description: nil,\n          name: \"y\",\n          path: URI.parse(\"#/definitions/point/properties/y\"),\n          type: :number\n        },\n        \"http://example.com/definitions.json#color\" =\u003e %JsonSchema.Types.EnumType{\n          description: nil,\n          name: \"color\",\n          path: URI.parse(\"#/definitions/color\"),\n          type: :string,\n          values: [\"red\", \"yellow\", \"green\", \"blue\"]\n        },\n        \"http://example.com/definitions.json#point\" =\u003e %JsonSchema.Types.ObjectType{\n          additional_properties: nil,\n          description: nil,\n          name: \"point\",\n          path: URI.parse(\"#/definitions/point\"),\n          pattern_properties: %{},\n          properties: %{\n            \"x\" =\u003e URI.parse(\"#/definitions/point/properties/x\"),\n            \"y\" =\u003e URI.parse(\"#/definitions/point/properties/y\")\n          },\n          required: [\"x\", \"y\"]\n        }\n      }\n    }\n  }\n}\n```\n\nThe schema dictionary uses the schema ID (`URI`) as key and the parsed schema as\nvalue. Each parsed schema likewise contains a type dictionary, `types`, which\nuses the subschema path (`URI`) as key and the parsed subschema as value.\n\nIf there are no errors in the schema result, the parsed schema dictionary can\nthen be used in your own JSON schema tool as appropriate.\n\n### Resolving a JSON Schema type from an identifier\n\nUsing the example schema dictionary from the previous section, we can use the\n`JsonSchema.resolve_type` function to lookup a subschema associated contained\nthe schema dictionary. The `resolve_type` function expects:\n\n- the `identifier` of the subschema to lookup which can be either a fully\n  qualified identifier like `http://example.com/definitions.json#color`, a\n  relative identifier like `#color`, or a relative path like\n  `#/definitions/color` when resolving a subschema inside the same parent\n  schema.\n- the `parent` identifier of the subschema doing the lookup, needed for relative\n  lookups and better error messaging,\n- the enclosing schema definition, `schema_def`, of the subschema doing the\n  lookup, also needed for relative lookups and error messaging,\n- the `schema dictionary` of the whole set of schemas.\n\nIn the example below, we resolve the reference to `color`:\n\n```json\n\"color\": {\n  \"$ref\": \"http://example.com/definitions.json#color\"\n}\n```\n\nfrom the inside the `circle` subschema properties.\n\n```elixir\nschema_dict = schema_result.schema_dict\nschema_def = schema_dict[\"http://example.com/circle.json\"]\nparent = URI.parse(\"#/properties\")\nidentifier = URI.parse(\"#/properties/color\")\nlookup_result = JsonSchema.resolve_type(identifier, parent, schema_def, schema_dict)\n{:ok, {color_type, parent_schema_def}} = lookup_result\nparent_schema_def == schema_dict[\"http://example.com/circle.json\"]\ncolor_type\n%JsonSchema.Types.EnumType{\n    description: nil,\n    name: \"color\",\n    path: URI.parse(\"#/definitions/color\"),\n    type: :string,\n    values: [\"red\", \"yellow\", \"green\", \"blue\"]\n  }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragonwasrobot%2Fjson_schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdragonwasrobot%2Fjson_schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragonwasrobot%2Fjson_schema/lists"}