Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
64% | Total: 282 | All time: 7,595 This week: 73 |
Version | License | PHP version | Categories | |||
jsonschema-validator 1.0.0 | Freely Distributable | 5.4 | PHP 5, Data types, Validation |
Description | Author | |||||||||||||||||||||||||
This package can validate JSON data using a structure specification. Innovation Award
|
|
<?php |
This class validates JSON payloads by using predefined schema based on basic necessary data types. Data types validation can be extended by creating new classes and new constraints can be added by writing new functions in Constraints class.
This schema validator works on following types:
$_payLoadSchema = [
[
'node' => [
'name' => 'title',
'type' => 'text',
'required' => true,
'max_length' => 20
]
],
[
'node' => [
'name' => 'action',
'type' => 'text',
'required' => true,
'max_length' => 20,
'choices' => [
"CUSTOMER_DATA",
"CUSTOMER_CREATE"
]
]
],
[
'node' => [
'name' => 'transaction_amount',
'type' => 'numeric',
'required' => true,
'value_range' => [
'min_value' => 10,
'max_value' => 100
]
]
],
[
'node' => [
'name' => 'transaction_date',
'type' => 'choices',
'required' => true,
'choices' => [
"2018-01-01",
"2018-01-02"
]
]
],
[
'node' => [
'name' => 'customer_ids',
'type' => 'array',
'required' => true,
'max_item_count' => 2
]
],
[
'node' => [
'name' => 'is_active',
'type' => 'boolean',
'required' => false
]
],
[
'node' => [
'name' => 'additional_data',
'type' => 'object',
'sub_nodes' => [
['node' => [
'name' => 'additional_field_1',
'type' => 'text',
'max_length' => "100"
]],
['node' => [
'name' => 'additional_field_2',
'type' => 'numeric'
]]
]
]
]
];
$json_raw = '
{
"title": "This is titlle",
"action": "CUSTOMER_CREATE",
"transaction_amount": "44",
"transaction_date": "2018-01-01",
"customer_ids": [
1001,
1002,
1003
],
"is_active": true,
"additional_data": {
"additional_field_2": 10
}
}
';
<?php
$jsonschemavalidator = new JsonSchemaValidator();
$jsonschemavalidator->validateSchema($_payLoadSchema, $json_raw);
if($validated){
echo "JSON Validated";
} else {
echo "JSON not validated";
print_r($jsonschemavalidator->getErrors());
}
Files (16) |
File | Role | Description | ||
---|---|---|---|---|
JSONSchema (2 files, 1 directory) | ||||
Autoloader.php | Class | Class source | ||
example.php | Example | Example script | ||
index.php | Example | Example script | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (16) | / | JSONSchema |
File | Role | Description | ||
---|---|---|---|---|
TypeClasses (9 files) | ||||
JsonSchemaValidator.php | Class | Class source | ||
SchemaException.php | Class | Class source |
Files (16) | / | JSONSchema | / | TypeClasses |
File | Role | Description |
---|---|---|
Constraints.php | Class | Class source |
TypeArray.php | Class | Class source |
TypeBool.php | Class | Class source |
TypeCheck.php | Class | Class source |
TypeChoices.php | Class | Class source |
TypeDate.php | Class | Class source |
TypeNumeric.php | Class | Class source |
TypeText.php | Class | Class source |
TypeValidation.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
jsonschema-validator-2018-03-14.zip 11KB | |
jsonschema-validator-2018-03-14.tar.gz 5KB | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Ratings | ||||||||||||||||||||||||||||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.