{"id":26517376,"url":"https://github.com/namoshizun/goodjson","last_synced_at":"2026-05-09T09:35:08.082Z","repository":{"id":56689715,"uuid":"304055887","full_name":"namoshizun/goodjson","owner":"namoshizun","description":"Functional validators to check anything about your JSON with ease.","archived":false,"fork":false,"pushed_at":"2020-10-25T02:44:25.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-09T14:32:11.959Z","etag":null,"topics":["functional-programming","json","json-schema","python","validation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/namoshizun.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}},"created_at":"2020-10-14T15:22:04.000Z","updated_at":"2020-10-25T02:44:27.000Z","dependencies_parsed_at":"2022-08-15T23:20:45.473Z","dependency_job_id":null,"html_url":"https://github.com/namoshizun/goodjson","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namoshizun%2Fgoodjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namoshizun%2Fgoodjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namoshizun%2Fgoodjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namoshizun%2Fgoodjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/namoshizun","download_url":"https://codeload.github.com/namoshizun/goodjson/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244759936,"owners_count":20505716,"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":["functional-programming","json","json-schema","python","validation"],"created_at":"2025-03-21T08:19:56.691Z","updated_at":"2026-05-09T09:35:08.043Z","avatar_url":"https://github.com/namoshizun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoodJSON\nGoodJSON enables a way of building declarative JSON validation workflows through validator composition.\n\nComing up in v0.2.0\n* Return all validation errors found instead of early quitting.\n* Lazy run through of validators.\n* More higher order validators.\n\n## Installation\n* Require Python \u003e= 3.6.\n* Install from GitHub: `pip install git+https://github.com/namoshizun/goodjson.git@main`\n\n\n## Usage\n#### Validator Function\nA GoodJSON validator is a function with signature `Callable[..., Tuple[bool, ValidationFail]]`. It takes any data and returns True/False based its validity, and a `ValidationFail` object to tell exactly what value failed to meet which requirement. Each validator must accompany an `ErrorMessage`. For example, we can create a parameterizable validator that checks string prefix like below:\n\n```python\nfrom goodjson.errors import ErrorMessage\nfrom goodjson.types import ValidatorFunction, CheckerReturn\nfrom goodjson.decorators import validator\n\n\nprefix_not_found = ErrorMessage(\n    name='prefix_not_found',\n    description='Expected prefix {prefix} is not found'\n)\n\ndef has_prefix_value(begin_value: str) -\u003e ValidatorFunction:\n\n    @validator(prefix_not_found.format(prefix=begin_value))\n    def checker(value: str) -\u003e CheckerReturn:\n        # ...\n        # DO WHATEVER YOU WANT BECAUSE IT IS JUST A FUNCTION!\n        return value.startswith(begin_value)\n\n    return checker\n\n\nok, val_fail = has_prefix_value('GJ')('__notGood!')\n\"\"\"\nExpect \"val_fail\" to be printed as the following.\n\"path\" is a dollar-sign demilited string pointing where the erroneous value is at.\nEvery \"path\" always starts with \"_root_\" representing the validator's input data itself.\n\n{\n    'error': 'Expected prefix GJ is not found',\n    'data': {\n        'path': '_root_'\n        'value': '__notGood!'\n    }\n}\n\"\"\"\n```\n\n\n\n#### Primitive Validators\nThese are functions validating values of primitive JSON types (string, number, boolean and null). GoodJSON has already implemented several such validators such as `is_categorical`, `is_between`, `is_of_type` and `is_not_empty` etc, which can be imported from `goodjson.validators`. Check out ./examples/simple_schema.py for more examples.\n\n\n#### Higher Order Validators\nThey run a series of validators to name/value pair and list data structures. Using them, you can compose highly flexible and complex validations in a very exprssive manner. GoodJSON implements three higher order validators:\n\n* **foreach**: `(*validators: ValidatorFunction) -\u003e ValidatorFunction`, applies validators to each element of an iterable data.\n* **foreach_key**: `(OPTIONAL_KEYS=tuple(), **validators: List[ValidatorFunction]) -\u003e ValidatorFunction`, applies key-paired validators to a dict-like data.\n* **gj_all**: `(*validators: ValidatorFunction) -\u003e ValidatorFunction`, feeds the input data to each validator and passes if all validators return no error.\n\nBelow is an example of building a JSON validation through validator composition. Check out ./examples/complex_schema.py for more examples.\n\n```python\n# ... reusing the has_prefix_value defined before\nfrom goodjson.validators import foreach_key, foreach, is_string, is_list\n\nis_good_json = foreach_key(\n    codes=[\n        is_list(),\n        foreach(is_string, has_prefix_value('GJ_'))\n    ]\n)\n\nok, val_fail = is_good_json({ 'codes': ['GJ_00001', '_00010'] })\n\"\"\"\nExpect \"val_fail\" to be printed as: \n\n{\n    \"error\": \"Expected prefix GJ_ is not found\",\n    \"data\": {\n        \"path\" : \"_root_$codes$1\",\n        \"value\": \"_00010\"\n    }\n}\n\"\"\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamoshizun%2Fgoodjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnamoshizun%2Fgoodjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamoshizun%2Fgoodjson/lists"}