[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8483":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":29,"discoverSource":30},8483,"json-schema","jsonrainbow\u002Fjson-schema","jsonrainbow","JSON Schema for PHP","https:\u002F\u002Fjsonrainbow.github.io\u002Fdocs\u002F",null,"PHP",3631,369,45,10,0,2,59.9,"MIT License",false,"main",true,[24,25],"json","schema","2026-06-12 04:00:39","# JSON Schema for PHP\n\n[![Build Status](https:\u002F\u002Fgithub.com\u002Fjsonrainbow\u002Fjson-schema\u002Factions\u002Fworkflows\u002Fcontinuous-integration.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fjsonrainbow\u002Fjson-schema\u002Factions)\n[![Latest Stable Version](https:\u002F\u002Fposer.pugx.org\u002Fjustinrainbow\u002Fjson-schema\u002Fv\u002Fstable)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fjustinrainbow\u002Fjson-schema)\n[![Total Downloads](https:\u002F\u002Fposer.pugx.org\u002Fjustinrainbow\u002Fjson-schema\u002Fdownloads)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fjustinrainbow\u002Fjson-schema\u002Fstats)\n![Supported Dialects](https:\u002F\u002Fimg.shields.io\u002Fendpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Fphp-justinrainbow-json-schema%2Fsupported_versions.json)\n\nA PHP Implementation for validating `JSON` Structures against a given `Schema` with support for `Schemas` of Draft-3,\nDraft-4, Draft-6 or Draft-7.\n\nFeatures of newer Drafts might not be supported. See [Table of All Versions of Everything](https:\u002F\u002Fjson-schema.org\u002Fspecification-links.html#table-of-all-versions-of-everything) to get an overview\nof all existing Drafts. See [json-schema](http:\u002F\u002Fjson-schema.org\u002F) for more details about the JSON Schema specification\n\n# Compliance\n![Draft 3](https:\u002F\u002Fimg.shields.io\u002Fendpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Fphp-justinrainbow-json-schema%2Fcompliance%2Fdraft3.json)\n![Draft 4](https:\u002F\u002Fimg.shields.io\u002Fendpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Fphp-justinrainbow-json-schema%2Fcompliance%2Fdraft4.json)\n![Draft 6](https:\u002F\u002Fimg.shields.io\u002Fendpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Fphp-justinrainbow-json-schema%2Fcompliance%2Fdraft6.json)\n![Draft 7](https:\u002F\u002Fimg.shields.io\u002Fendpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Fphp-justinrainbow-json-schema%2Fcompliance%2Fdraft7.json)\n\n\n## Installation\n\n### Library\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fjsonrainbow\u002Fjson-schema.git\n```\n\n### Composer\n\n[Install PHP Composer](https:\u002F\u002Fgetcomposer.org\u002Fdoc\u002F00-intro.md)\n\n```bash\ncomposer require justinrainbow\u002Fjson-schema\n```\n\n## Usage\n\nFor a complete reference see [Understanding JSON Schema](https:\u002F\u002Fjson-schema.org\u002Funderstanding-json-schema\u002F).\n\n__Note:__ Not all drafts might be supported, check the [Bowtie report](https:\u002F\u002Fbowtie.report\u002F#\u002Fimplementations\u002Fphp-justinrainbow-json-schema) on the current state of draft implementations.\n\n### Basic usage\n\n```php\n\u003C?php\n\n$data = json_decode(file_get_contents('data.json'), false);\n\n\u002F\u002F Validate\n$validator = new JsonSchema\\Validator();\n$validator->validate($data, (object)['$ref' => 'file:\u002F\u002F' . realpath('schema.json')]);\n\nif ($validator->isValid()) {\n    echo \"The supplied JSON validates against the schema.\\n\";\n} else {\n    echo \"JSON does not validate. Violations:\\n\";\n    foreach ($validator->getErrors() as $error) {\n        printf(\"[%s] %s\\n\", $error['property'], $error['message']);\n    }\n}\n```\n\n### Type coercion\n\nIf you're validating data passed to your application via HTTP, you can cast strings and booleans to\nthe expected types defined by your schema:\n\n```php\n\u003C?php\n\nuse JsonSchema\\SchemaStorage;\nuse JsonSchema\\Validator;\nuse JsonSchema\\Constraints\\Factory;\nuse JsonSchema\\Constraints\\Constraint;\n\n$request = (object)[\n    'processRefund'=>\"true\",\n    'refundAmount'=>\"17\"\n];\n\n$validator->validate(\n    $request, (object) [\n        \"type\"=>\"object\",\n        \"properties\"=>(object)[\n            \"processRefund\"=>(object)[\n                \"type\"=>\"boolean\"\n            ],\n            \"refundAmount\"=>(object)[\n                \"type\"=>\"number\"\n            ]\n        ]\n    ],\n    Constraint::CHECK_MODE_COERCE_TYPES\n); \u002F\u002F validates!\n\nis_bool($request->processRefund); \u002F\u002F true\nis_int($request->refundAmount); \u002F\u002F true\n```\n\nA shorthand method is also available:\n```PHP\n$validator->coerce($request, $schema);\n\u002F\u002F equivalent to $validator->validate($data, $schema, Constraint::CHECK_MODE_COERCE_TYPES);\n```\n\n### Default values\n\nIf your schema contains default values, you can have these automatically applied during validation:\n\n```php\n\u003C?php\n\nuse JsonSchema\\Validator;\nuse JsonSchema\\Constraints\\Constraint;\n\n$request = (object)[\n    'refundAmount'=>17\n];\n\n$validator = new Validator();\n\n$validator->validate(\n    $request,\n    (object)[\n        \"type\"=>\"object\",\n        \"properties\"=>(object)[\n            \"processRefund\"=>(object)[\n                \"type\"=>\"boolean\",\n                \"default\"=>true\n            ]\n        ]\n    ],\n    Constraint::CHECK_MODE_APPLY_DEFAULTS\n); \u002F\u002Fvalidates, and sets defaults for missing properties\n\nis_bool($request->processRefund); \u002F\u002F true\n$request->processRefund; \u002F\u002F true\n```\n\n### With inline references\n\n```php\n\u003C?php\n\nuse JsonSchema\\SchemaStorage;\nuse JsonSchema\\Validator;\nuse JsonSchema\\Constraints\\Factory;\n\n$jsonSchema = \u003C\u003C\u003C'JSON'\n{\n    \"type\": \"object\",\n    \"properties\": {\n        \"data\": {\n            \"oneOf\": [\n                { \"$ref\": \"#\u002Fdefinitions\u002FintegerData\" },\n                { \"$ref\": \"#\u002Fdefinitions\u002FstringData\" }\n            ]\n        }\n    },\n    \"required\": [\"data\"],\n    \"definitions\": {\n        \"integerData\" : {\n            \"type\": \"integer\",\n            \"minimum\" : 0\n        },\n        \"stringData\" : {\n            \"type\": \"string\"\n        }\n    }\n}\nJSON;\n\n\u002F\u002F Schema must be decoded before it can be used for validation\n$jsonSchemaObject = json_decode($jsonSchema);\n\n\u002F\u002F The SchemaStorage can resolve references, loading additional schemas from file as needed, etc.\n$schemaStorage = new SchemaStorage();\n\n\u002F\u002F This does two things:\n\u002F\u002F 1) Mutates $jsonSchemaObject to normalize the references (to file:\u002F\u002FmySchema#\u002Fdefinitions\u002FintegerData, etc)\n\u002F\u002F 2) Tells $schemaStorage that references to file:\u002F\u002FmySchema... should be resolved by looking in $jsonSchemaObject\n$schemaStorage->addSchema('file:\u002F\u002FmySchema', $jsonSchemaObject);\n\n\u002F\u002F Provide $schemaStorage to the Validator so that references can be resolved during validation\n$jsonValidator = new Validator(new Factory($schemaStorage));\n\n\u002F\u002F JSON must be decoded before it can be validated\n$jsonToValidateObject = json_decode('{\"data\":123}');\n\n\u002F\u002F Do validation (use isValid() and getErrors() to check the result)\n$jsonValidator->validate($jsonToValidateObject, $jsonSchemaObject);\n```\n\n### Configuration Options\nA number of flags are available to alter the behavior of the validator. These can be passed as the\nthird argument to `Validator::validate()`, or can be provided as the third argument to\n`Factory::__construct()` if you wish to persist them across multiple `validate()` calls.\n\n| Flag                                            | Description                                                     |\n|-------------------------------------------------|-----------------------------------------------------------------|\n| `Constraint::CHECK_MODE_NORMAL`                 | Validate in 'normal' mode - this is the default                 |\n| `Constraint::CHECK_MODE_TYPE_CAST`              | Enable fuzzy type checking for associative arrays and objects   |\n| `Constraint::CHECK_MODE_COERCE_TYPES` [^1][^2]  | Convert data types to match the schema where possible           |\n| `Constraint::CHECK_MODE_EARLY_COERCE` [^2]      | Apply type coercion as soon as possible                         |\n| `Constraint::CHECK_MODE_APPLY_DEFAULTS` [^1]    | Apply default values from the schema if not set                 |\n| `Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS` | When applying defaults, only set values that are required       |\n| `Constraint::CHECK_MODE_EXCEPTIONS`             | Throw an exception immediately if validation fails              |\n| `Constraint::CHECK_MODE_DISABLE_FORMAT`         | Do not validate \"format\" constraints                            |\n| `Constraint::CHECK_MODE_VALIDATE_SCHEMA`        | Validate the schema as well as the provided document            |\n| `Constraint::CHECK_MODE_STRICT` [^3]            | Validate the scheme using strict mode using the specified draft |\n\n[^1]: Please note that using `CHECK_MODE_COERCE_TYPES` or `CHECK_MODE_APPLY_DEFAULTS` will modify your\noriginal data.\n[^2]: `CHECK_MODE_EARLY_COERCE` has no effect unless used in combination with `CHECK_MODE_COERCE_TYPES`. If\nenabled, the validator will use (and coerce) the first compatible type it encounters, even if the\nschema defines another type that matches directly and does not require coercion.\n[^3]: `CHECK_MODE_STRICT` only can be used for Draft-6 at this point.\n\n## Running the tests\n\n```bash\ncomposer test                            # run all unit tests\ncomposer testOnly TestClass              # run specific unit test class\ncomposer testOnly TestClass::testMethod  # run specific unit test method\ncomposer style-check                     # check code style for errors\ncomposer style-fix                       # automatically fix code style errors\n```\n\n# Contributors  ✨\nThanks go to these wonderful people, without their effort this project wasn't possible.\n\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fjsonrainbow\u002Fjson-schema\u002Fgraphs\u002Fcontributors\">\n  \u003Cimg src=\"https:\u002F\u002Fcontrib.rocks\u002Fimage?repo=jsonrainbow\u002Fjson-schema\" \u002F>\n\u003C\u002Fa>\n","jsonrainbow\u002Fjson-schema 是一个用于 PHP 的 JSON Schema 验证库，支持 Draft-3、Draft-4、Draft-6 和 Draft-7 规范。其核心功能是根据给定的 JSON Schema 对 JSON 数据结构进行验证，并提供了类型转换功能，可以将字符串和布尔值转换为 schema 中定义的预期类型。该库适用于需要确保 JSON 数据符合预定义模式的各种场景，例如 API 请求响应验证、数据导入导出过程中的格式校验等。通过 Composer 可以方便地安装并集成到现有 PHP 项目中。","2026-06-11 03:18:15","top_language"]