https://github.com/oguzhanunlu/validate_json
Restful service to validate JSON docs against JSON schemas
https://github.com/oguzhanunlu/validate_json
django json python restful-api
Last synced: about 1 year ago
JSON representation
Restful service to validate JSON docs against JSON schemas
- Host: GitHub
- URL: https://github.com/oguzhanunlu/validate_json
- Owner: oguzhanunlu
- License: apache-2.0
- Created: 2017-10-19T15:27:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-19T21:15:46.000Z (over 8 years ago)
- Last Synced: 2025-02-23T11:14:34.497Z (over 1 year ago)
- Topics: django, json, python, restful-api
- Language: Python
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# validate_json
Restful service to validate JSON docs against JSON schemas
### Prerequisities
* Python 2.7
* pip
* virtualenv
* virtualenvwrapper
### Installing && Running
* Clone project, `git clone git@github.com:oguzhanunlu/validate_json.git`
* Create a python2.7 virtual environment
* Inside environment, run `pip install -r requirements.txt`, to install depencencies.
* At the root of the project, start Django runserver, `python manage.py runserver`
Now server is up and running at 8000 port.
### API Endpoints
```
POST /schema/SCHEMAID - Upload JSON Schema with unique `SCHEMAID`
GET /schema/SCHEMAID - Download JSON Schema with unique `SCHEMAID`
POST /validate/SCHEMAID - Validate JSON document against the JSON Schema identified by `SCHEMAID`
```
### Use case
User has a JSON file `config.json` as following:
```json
{
"source": "/home/alice/image.iso",
"destination": "/mnt/storage",
"timeout": null,
"chunks": {
"size": 1024,
"number": null
}
}
```
And expects it conforms to the following JSON Schema `config-schema.json`, after cleaned from keys where value is None:
```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"source": {
"type": "string"
},
"destination": {
"type": "string"
},
"timeout": {
"type": "integer",
"minimum": 0,
"maximum": 32767
},
"chunks": {
"type": "object",
"properties": {
"size": {
"type": "integer"
},
"number": {
"type": "integer"
}
},
"required": ["size"]
}
},
"required": ["source", "destination"]
}
```
To check that it really fits the schema:
1. Upload the JSON Schema: `curl http://localhost:8000/schema/config-schema -X POST -d @config-schema.json`
2. Response will be: `{"action": "uploadSchema", "id": "config-schema", "status": "success"}` and status code 201
3. Upload the JSON document to validate it `curl http://localhost:8000/validate/config-schema -X POST -d @config.json`
4. Response will be: `{"action": "validateDocument", "id": "config-schema", "status": "success"}` and status code 200