Commit 7c2da936 authored by Sven Franck's avatar Sven Franck Committed by GitHub

Merge pull request #9 from slaimu/master

fix json shema validator
parents 0b9e1af8 accd8363
{
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"location": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "name"
},
"address": {
"type": "string",
"description": "Company address"
},
"postal-code": {
"description": "Postal code must be composed of 5 numbers equal or greater than 0",
"type": "string"
},
"city": {
"type": "string",
"description": "name"
},
"country": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"phone_contact": {
"description": "Phone number which must be equal to or greater than zero preceded by +",
"type": "string"
},
"mail_contact": {
"description": "",
"type": "string"
},
"coordinate_list": {
"description": "Geographical coordinates of the company",
"type": "array"
}
}
},
"subsidiary_location_list": {
"type": "array",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"website_url": {
"type": "string"
},
"founded_year": {
"type": "integer"
},
"KPI": {
"type": "array",
"properties": {
"year": {
"type": "integer"
},
"staff": {
"type": "number"
},
"earnings": {
"type": "string",
"pattern": "\\d*\\s{1}[A-Z]{3}",
"description": "The ISO 4217 currency code."
},
"total_assets": {
"type": "string",
"pattern": "\\d*\\s{1}[A-Z]{3}",
"description": "The ISO 4217 currency code."
},
"revenues": {
"type": "string",
"pattern": "\\d*\\s{1}[A-Z]{3}",
"description": "The ISO 4217 currency code."
},
"source_url": {
"type": "string"
}
}
},
"solution_list": {
"type": "array",
"properties": {
"title": {
"type": "string"
},
"logo_url": {
"type": "string"
},
"website_url": {
"type": "string"
},
"created_year": {
"type": "integer"
},
"description": {
"type": "string"
},
"category_list": {
"type": "array",
"category": {
"enum": ["Storage and database", "Compute virtualisation", "Desktop virtualisation", "vRan", "Operation management", "Service lifecycle automation", "Networking", "Identity", "Cybersecurity", "Application", "Workspace", "Developer environment", "Developer API", "Communication", "IoT and industrial", "Big Data Hub", "Server", "Switch", "Router", "Rack", "Cooling", "CPU", "Radio"]
}
},
"similar_solution_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"similar_solution_url": {
"type": "string"
},
"category": {
"type": "string"
}
}
}
},
"floss_software": {
"type": "boolean"
},
"commercial_support_open_source_version": {
"type": "boolean"
},
"commercial_support_available":{
"type": "boolean"
},
"wikipedia_url": {
"type": "string"
},
"reference_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"logo_url": {
"type": "string"
},
"country": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"industry": {
"type": "string"
}
}
},
"success_case_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"image_url": {
"type": "string"
},
"industry": {
"type": "string",
"industry": {
"enum": ["Academia and Research", "Agriculture and Food", "Associations and NGOs", "Aviation and Aerospace", "Automotive", "Banking and Finance", "Chemicals", "Commerce and Retail", "Construction", "Consulting and Training", "Defense", "Education", "Energy and Utilities", "Health and Life Sciences", "Housing and Real Estate", "Insurance", "Information Technology", "Manufacturing", "Media and Entertainment", "Public Administration and Government", "Telecommunication", "Transport", "Travel and Tourism"]
},
"customer": {
"type": "string"
},
"country": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"language": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO language code"
},
"success_case_url": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
[
{
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"created": {
"type": "string"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"logo_url": {
"type": "string"
},
"location": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "name"
},
"address": {
"type": "string",
"description": "Company address"
},
"postal-code": {
"description": "Postal code must be composed of 5 numbers equal or greater than 0",
"type": "string"
},
"city": {
"type": "string",
"description": "name"
},
"country": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"phone_contact": {
"description": "Phone number which must be equal to or greater than zero preceded by",
"type": "string"
},
"mail_contact": {
"description": "",
"type": "string"
},
"coordinate_list": {
"description": "Geographical coordinates of the company",
"type": "array"
}
}
},
"subsidiary_location_list": {
"type": "array",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"website_url": {
"type": "string"
},
"founded_year": {
"type": "string"
},
"kpi_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"year": {
"type": "string"
},
"staff": {
"type": "string"
},
"earnings": {
"type": "string",
"description": "The ISO 4217 currency code."
},
"total_assets": {
"type": "string",
"description": "The ISO 4216 currency code."
},
"revenues": {
"type": "string",
"description": "The ISO 4217 currency code."
},
"source_url": {
"type": "string"
}
}
}
},
"solution_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"logo_url": {
"type": "string"
},
"website_url": {
"type": "string"
},
"created_year": {
"type": "string"
},
"description": {
"type": "string"
},
"category_list": {
"type": "array",
"items": {
"enum": [
"Storage and database",
"Compute virtualisation",
"Desktop virtualisation",
"vRan",
"Operation management",
"Service lifecycle automation",
"Networking",
"Identity",
"Cybersecurity",
"Application",
"Workspace",
"Developer environment",
"Developer API",
"Communication",
"IoT and industrial",
"Big Data Hub",
"Server",
"Switch",
"Router",
"Rack",
"Cooling",
"CPU",
"Radio"
]
}
},
"similar_solution_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"similar_solution_url": {
"type": "string"
},
"category": {
"type": "string"
}
}
}
},
"source_code_download": {
"type": "string"
},
"source_code_profile": {
"type": "string"
},
"commercial_support_url": {
"type": "string"
},
"floss_software": {
"type": "boolean"
},
"commercial_support_open_source_version": {
"type": "boolean"
},
"commercial_support_available": {
"type": "boolean"
},
"wikipedia_url": {
"type": "string"
},
"reference_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"logo_url": {
"type": "string"
},
"country": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"industry": {
"type": "string"
}
}
}
},
"success_case_list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"image_url": {
"type": "string"
},
"industry": {
"enum": [
"Academia and Research",
"Agriculture and Food",
"Associations and NGOs",
"Aviation and Aerospace",
"Automotive",
"Banking and Finance",
"Chemicals",
"Commerce and Retail",
"Construction",
"Consulting and Training",
"Defense",
"Education",
"Energy and Utilities",
"Health and Life Sciences",
"Housing and Real Estate",
"Insurance",
"Information Technology",
"Manufacturing",
"Media and Entertainment",
"Public Administration and Government",
"Telecommunication",
"Transport",
"Travel and Tourism"
]
},
"customer": {
"type": "string"
},
"country": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO country code (ISO 3166-1 alpha-2)"
},
"language": {
"type": "string",
"pattern": "^[A-Z]{2}$",
"description": "A valid 2-digit ISO language code"
},
"success_case_url": {
"type": "string"
}
}
}
}
}
}
}
}
}
]
heres a script to run the checks:
```
#!/usr/bin/env python3
import glob, json, os
import glob, json, os, sys
from jsonschema import validate
from jsonschema.exceptions import ValidationError
......@@ -13,27 +8,36 @@ SCHEMA = json.load(open("data/JSON-schema.json"))
num_valid = 0
filenames = sorted(glob.glob("data/*.json"))
for fn in filenames:
if fn == "data/JSON-schema.json":
continue
if len(sys.argv) > 1:
filenames = sys.argv[1:]
else:
filenames = sorted(glob.glob("*.json"))
incorrect_json_list = []
invalid_json_list = []
for fn in filenames:
try:
data = json.load(open(fn))
except:
print(f"{fn} -> syntactically incorrect JSON")
incorrect_json_list.append(fn)
continue
try:
validate(instance=data, schema=SCHEMA[0])
except ValidationError as e:
print(f"{fn} -> invalid JSON")
print(" " + e.message)
invalid_json_list.append({"file":fn, "error": e.message})
continue
print(f"{fn} -> OK")
num_valid += 1
print(f"{num_valid} valid JSON files")
```
print(f"{num_valid} valid JSON files\n")
print("\nfollowing file are incorrect:\n")
for fn in incorrect_json_list:
print(f"{fn}")
print("\nfollowing file are invalide:\n")
for fn in invalid_json_list:
print(f"{fn['file']}: {fn['error']}")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment