JSON Validation Service (REST) allows you to validate JSON documents against JSON Schemas.
$ pip install jsonify
$ pip install flask
$ pip install json-schema
$ python home.py
- Upload JSON Schema with unique
SCHEMAID
Example 1: Upload a valid JSON Schema
curl -X POST -F file=@schema_sample.json http://127.0.0.1:5000/schema/snow
Output:
{
"action": "uploadSchema",
"id": "snow",
"status": "success"
}
Example 2: Upload invalid JSON Schema
curl -X POST -F file=@schema_sample.json http://127.0.0.1:5000/schema/snow
Output:
{
"action": "uploadSchema",
"id": "snow",
"message": "Invalid JSON File",
"status": "error"
- Validate JSON document against JSON Schema
SCHEMAID
Example 1: Validate a JSON file (success)
curl -X POST -F [email protected] http://127.0.0.1:5000/validate/snow
{
"action": "validateDocument",
"id": "snow",
"status": "success"
}
Example 2: Validate a JSON file (failure -- incase the file fails validation)
curl -X POST -F [email protected] http://127.0.0.1:5000/validate/snow
{
"action": "validateDocument",
"id": "snow",
"message": "u'ABC' is not of type u'number'",
"status": "error"
}
- Download JSON Schema with unique
SCHEMAID
Example:
curl -X GET http://127.0.0.1:5000/schema/snow
{
"type":"object",
"$schema": "http://json-schema.org/draft-03/schema",
"required":false,
"properties":{
"address": {
"type":"object",
"required":true,
"properties":{
"city": {
"type":"string",
"required":true
},
"houseNumber": {
"type":"number",
"required":false
},
"streetAddress": {
"type":"string",
"required":true
}
}
},
"phoneNumber": {
"type":"array",
"required":false,
"items":
{
"type":"object",
"required":false,
"properties":{
"number": {
"type":"string",
"required":false
},
"type": {
"type":"string",
"required":false
}
}
}
}
}
}
-
All the schema files are currently being uploaded to the current working directory. This can be changed as per the requirements, and we can create a dedicated directory for storing all the schemas.
-
Code needs to be refactored as per PEP-8 standards.
-
Currently files cannot be uploaded using the -d flag, and the -f flag is being used. I'm trying to debug this issue.
- Add Unit tests