{"id":36994063,"url":"https://github.com/joipolloi/json-validation-bundle","last_synced_at":"2026-01-13T23:46:17.662Z","repository":{"id":57001052,"uuid":"90761495","full_name":"joipolloi/json-validation-bundle","owner":"joipolloi","description":"Symfony framework bundle providing an annotation for validating JSON passed with a request against a schema","archived":false,"fork":false,"pushed_at":"2023-03-30T20:14:28.000Z","size":35,"stargazers_count":5,"open_issues_count":1,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-07-23T16:51:01.593Z","etag":null,"topics":["bundle","json","json-schema","json-validation","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/joipolloi.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-05-09T15:21:24.000Z","updated_at":"2020-06-29T14:42:48.000Z","dependencies_parsed_at":"2024-11-14T16:30:27.090Z","dependency_job_id":"4ab98b2c-3f4e-4576-991c-935d990b29af","html_url":"https://github.com/joipolloi/json-validation-bundle","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"7776346ea202adbb2affd0396dcbce0235fe2483"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/joipolloi/json-validation-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joipolloi%2Fjson-validation-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joipolloi%2Fjson-validation-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joipolloi%2Fjson-validation-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joipolloi%2Fjson-validation-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joipolloi","download_url":"https://codeload.github.com/joipolloi/json-validation-bundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joipolloi%2Fjson-validation-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["bundle","json","json-schema","json-validation","php","symfony","symfony-bundle"],"created_at":"2026-01-13T23:46:17.084Z","updated_at":"2026-01-13T23:46:17.652Z","avatar_url":"https://github.com/joipolloi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Validation Bundle\n\n[![Build Status](https://api.travis-ci.org/joipolloi/json-validation-bundle.svg)](https://travis-ci.org/joipolloi/json-validation-bundle)\n\nA Symfony bundle that provides an annotation to validate JSON passed to a controller action against a schema.\n\n## Usage\n\nWhen creating a controller method that accepts JSON as input (e.g. a POST method), put the `@ValidateJson` annotation on your action and point to the schema to validate against.\n\n```php\nuse JoiPolloi\\Bundle\\JsonValidationBundle\\Annotation\\ValidateJson\n\nclass MyController\n{\n    /**\n     * @ValidateJson(\"@MyBundle/Resources/schema/action-schema.json\")\n     */\n    public function myAction()\n    {\n        // ...\n    }\n}\n```\n\nNow any time the action is called, the passed JSON will be validated against the schema. If there are no validation errors, the action will execute as normal. If there are errors then a 400 (bad request) response will be returned.\n\n## Installation\n\nUse composer: `composer require joipolloi/json-validation-bundle`\n\nOpen `AppKernel.php` in your Symfony project:\n\n```php\n$bundles = array(\n    // ...\n    new JoiPolloi\\Bundle\\JsonValidationBundle\\JsonValidationBundle(),\n    // ...\n);\n```\n\n## Configuration\n\nThe only configuration option is whether to enable the application/problem+json event listener. This is described in detail below, it defaults to off, but can be enabled with the following configuration in your config.yml:\n\n```yml\njoipolloi_jsonvalidation:\n    enable_problemjson_listener: true\n```\n\n## Details\n\nBehind the scenes the bundle registers an event listener on the `kernel.controller` event that will validate the request content (i.e. `$request-\u003egetContent();`) against a JSON schema using the [justinrainbow/json-schema](https://github.com/justinrainbow/json-schema) library.\n\nIf there is an issue locating the JSON schema, decoding the JSON, decoding the JSON schema or validating against the JSON, a [JsonValidationException](Exception/JsonValidationException.php) (which extends BadRequestHttpException) is thrown with an error message.\n\n## Options\n\n### Getting the valid JSON\n\nIn order to save time and processing, you can get the validated JSON as an object by getting the `validJson` attribute on a request, or by putting `$validJson` as an argument to your action:\n\n```php\n/**\n * @ValidateJson(\"@MyBundle/Resources/schema/action-schema.json\")\n */\npublic function myAction(Request $request, $validJson)\n{\n    // $request-\u003eattributes-\u003eget('validJson') === $validJson\n}\n```\n\nIf you want the decoded JSON as an associative array or use the [Symfony form component](http://symfony.com/doc/current/forms.html), type hint `$validJson` as an array:\n\n```php\n/**\n * @ValidateJson(\"@MyBundle/Resources/schema/action-schema.json\")\n */\npublic function myAction(array $validJson)\n{\n    $form = $this-\u003ecreateForm(MyFormType::class);\n    $form-\u003esubmit($validJson);\n\n    if ($form-\u003eisValid()) {\n        // ...\n    }\n}\n```\n\nThis does incur a slight performance overhead versus getting an object as the JSON needs to be decoded twice: once to validate against the JSON schema and again as an associative array. If your JSON is large but only a single level deep then you may get better performance by just casting to an array:\n\n```php\npublic function myAction($validJson)\n{\n    // ...\n    $form-\u003esubmit((array)$validJson);\n}\n```\n\n### Specifying the HTTP methods to validate upon\n\nIf your controller action listens on multiple HTTP methods (e.g. PUT and POST) and you only want to validate the JSON on one of them, you can use the `methods` parameter to the annotation:\n\n```php\n/**\n * @ValidateJson(\"@MyBundle/Resources/schema/action-schema.json\", methods={\"POST\"})\n */\npublic function myAction(Request $request, $validJson = null)\n{\n    if ($request-\u003eisMethod('POST')) {\n        // $validJson !== null\n    }\n}\n```\n\n### Allowing for empty as a valid value\n\nIf for some reason you want to allow empty content to also be valid, use the `emptyIsValid` parameter to the annotation:\n\n```php\n/**\n * @ValidateJson(\"@MyBundle/Resources/schema/action-schema.json\", emptyIsValid=true)\n */\npublic function myAction($validJson = null)\n{\n    // ...\n}\n```\n\nNote that only empty request content will be classed as valid; if empty but syntactically valid JSON is passed, this will still be validated against the schema (i.e. \"{}\" will not be counted as empty).\n\n## application/problem+json responses\n\nAn exception listener is included within the bundle that can send an `application/problem+json` response as detailed in [RFC 7807](https://tools.ietf.org/html/rfc7807). The listener is turned off by default to allow for your own application to handle the exception but can be turned on with configuration in your config.yml file:\n\n```yml\njoipolloi_jsonvalidation:\n    enable_problemjson_listener: true\n```\n\nIf the listener is disabled, a 400 bad request exception is thrown and caught as per your application. If turned on and there is a problem decoding or validating the JSON, a response might look like:\n\n```json\n{\n    \"status\": 400,\n    \"title\": \"Unable to parse\\/validate JSON\",\n    \"detail\": \"There was a problem with the JSON that was sent with the request\",\n    \"errors\": [\n        {\n            \"message\": \"[4] Syntax error\"\n        }\n    ]\n}\n```\n\nThe \"errors\" key will be an array of at least one error. Each error will be an object with at least a \"message\" key, but may additionally have \"constraint\", \"pointer\" and \"property\" keys with useful information.\n\nWhile errors within this array should be safe to send back to the client, there may be some information leakage with regards paths - either to the schema or referenced files. If in doubt, disable the listener and roll your own to have more control.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoipolloi%2Fjson-validation-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoipolloi%2Fjson-validation-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoipolloi%2Fjson-validation-bundle/lists"}