# JSONvv JSON value validator ## Overview This is a simple JSON schema validator library. It was created for Camoufox to validate passed user configurations. Because I found it useful for other projects, I decided to extract it into a separate library. JSONvv's syntax parser is written in pure Python. It does not rely on any dependencies. ### Example
| Configuration | Validator |
|---|---|
| ```python config = { "username": "johndoe", "email": "johndoe@example.com", "age": 30, "chat": "Hello world!", "preferences": { "notifications": True, "theme": "dark" }, "allowed_commands": [ "/help", "/time", "/weather" ], "location": [40.7128, -74.0060], "hobbies": [ { "name": "Traveling", "cities": ["Paris", "London"] }, { "name": "reading", "hours": { "Sunday": 2, "Monday": 3, } } ] } ``` | ```python validator = { "username": "str", # Basic username "email": "str[/\S+@\S+\.\S+/]", # Validate emails "age": "int[>=18]", # Age must be 18 or older "chat": "str | nil", # Optional chat message "preferences": { "notifications": "bool", "theme": "str[light, dark] | nil", # Optional theme }, # Commands must start with "/", but not contain "sudo" "allowed_commands": "array[str[/^//] - str[/sudo/]]", # Validate coordinate ranges "location": "tuple[double[-90 - 90], double[-180 - 180]]", # Handle an array of hobby types "hobbies": "array[@traveling | @other, >=1]", "@traveling": { # Require 1 or more cities/countries iff name is "Traveling" "*name,type": "str[Traveling]", "*cities,countries": "array[str[A-Za-z*], >=1]", }, "@other": { "name,type": "str - str[Traveling]", # Non-traveling types # If hour(s) is specified, require days have >0 hours "/hours?/": { "*/day$/": "int[>0]" } } } ``` |