{"id":20466058,"url":"https://github.com/rizerphe/json-schema-enforcer","last_synced_at":"2025-09-24T22:31:23.370Z","repository":{"id":176530651,"uuid":"658443806","full_name":"rizerphe/json-schema-enforcer","owner":"rizerphe","description":"A progressive JSON schema validator","archived":false,"fork":false,"pushed_at":"2023-09-02T06:01:48.000Z","size":19,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T22:51:32.951Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rizerphe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-25T18:56:34.000Z","updated_at":"2024-06-08T00:17:27.000Z","dependencies_parsed_at":"2024-11-15T13:32:29.939Z","dependency_job_id":null,"html_url":"https://github.com/rizerphe/json-schema-enforcer","commit_stats":null,"previous_names":["rizerphe/json-schema-enforcer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rizerphe/json-schema-enforcer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fjson-schema-enforcer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fjson-schema-enforcer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fjson-schema-enforcer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fjson-schema-enforcer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rizerphe","download_url":"https://codeload.github.com/rizerphe/json-schema-enforcer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fjson-schema-enforcer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276828572,"owners_count":25712007,"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","status":"online","status_checked_at":"2025-09-24T02:00:09.776Z","response_time":97,"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":[],"created_at":"2024-11-15T13:21:20.282Z","updated_at":"2025-09-24T22:31:23.083Z","avatar_url":"https://github.com/rizerphe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON schema enforcer\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Key Features](#key-features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Example JSON Schema](#example-json-schema)\n- [Potential Use Cases](#potential-use-cases)\n\n## Introduction\n\njson-schema-enforcer is a Python package that allows you to progressively validate a JSON string against a JSON schema. With this package, you can check if a JSON string adheres to the schema and if it is complete, even if the string is not fully formed. This is particularly useful when working with large language models to constraint text generation.\n\nThis project was created out of spite for the lack of a similar feature in [OpenAI ChatGPT's function calling](https://openai.com/blog/function-calling-and-other-api-updates), to prove that creating something like this is very easy. It uses the simplified JSON schema specification, similar to what OpenAI does. Please note that the code implementation probably does not adhere to best practices, as it is primarily an experimental showcase by someone who isn't skilled in creating programming language parsers.\n\n## Key Features\n\n- Parses a JSON schema and validates a string against it\n- Determines if the returned JSON is valid (matches the schema and optional formatting)\n- Determines if the JSON string is complete and provides the index of the last character\n\n## Installation\n\nYou can install json-schema-enforcer using pip:\n\n```shell\npip install json-schema-enforcer\n```\n\n## Usage\n\nTo use json-schema-enforcer in your Python project, follow these steps:\n\n```python\nimport json_schema_enforcer\n\n# Parse the schema\nparser = json_schema_enforcer.parser_for_schema(schema)\n\n# Check if the parser is valid\nif parser is None:\n    raise ValueError(\"Invalid JSON schema\")\n\n# Validate the JSON string\nvalidated = parser.validate(maybe_json_string)\n\n# Print the validation result\nprint(validated.valid)  # Whether it adheres to the schema\nprint(\"complete\" if validated.end_index else \"incomplete\")\n```\n\n## Example JSON Schema\n\nYou can use the following example JSON schema as a reference when working with json-schema-enforcer:\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"name\": { \"type\": \"string\", \"maxLength\": 20 },\n    \"age\": { \"type\": \"integer\" },\n    \"preferred_animal\": { \"type\": \"string\", \"enum\": [\"cat\", \"dog\"] }\n  },\n  \"required\": [\"name\", \"age\"]\n}\n```\n\n## Potential Use Cases\n\n- Constraining text generation with large language models; example: [local-llm-function-calling](https://github.com/rizerphe/local-llm-function-calling), a project that allows you to constrain generation with any huggingface model\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizerphe%2Fjson-schema-enforcer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frizerphe%2Fjson-schema-enforcer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizerphe%2Fjson-schema-enforcer/lists"}