JSON-Struct

JSON Struct is a vocabulary that allows you to annotate and validate JSON documents.

Examples

Basic

This is a simple example of vocabulary

examples/simple/struct.jsonc

{
    "$schema": "https://github.com/SamanFekri/JSON-Struct",
    "struct": {
        "firstname": "string", 
        "lastname": "string",
        "age": "int",
        "address": { 
            "line1": "string",
            "line2": "string",
            "city": "string",
            "country": "string"
        },
        "salary": "number", // in euros
        "is_happy": "boolean",
        "languages": ["string"]
    }
}

Multiple types

Defining a field with multiple type.(exp. string and int)

"id": "string|int"

Required

You can use required fields as below

{
    "$schema": "https://github.com/SamanFekri/JSON-Struct",
    "struct": {
        "firstname": "string",
        // ...
        "address": {
            "line1": "string",
            "line2": "string",
            "city": "string",
            "country": "string"
        },
        //...
    },
    "required": ["firstname", "address.country"] // firstname and address country arerequired
}

Types

  • Integer:int
  • Number: number
  • String: string
  • Boolean: boolean
  • JSON Object: (object, {})
    • Note: It also accepts nested objects
  • Array: ([], ["any"])
    • Example: ["string"] this is an array of string
    • Note: It also accepts nested arrays and array of objects
  • Anything: any

GitHub

View Github