{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "JSON Table Schema",
    "description": "JSON Schema for validating JSON Table structures",
    "type": "object",
    "properties": {
        "fields": {
            "type": "array",
            "minItems": 1,
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "title": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string"
                    },
                    "type": {
                        "enum": [
                            "string",
                            "number",
                            "integer",
                            "date",
                            "time",
                            "datetime",
                            "boolean",
                            "binary",
                            "object",
                            "geopoint",
                            "geojson",
                            "array",
                            "any"
                        ]
                    },
                    "format": {
                        "type": "string"
                    },
                    "constraints": {
                        "type": "object",
                        "properties": {
                            "required": {
                                "type": "boolean"
                            },
                            "minLength": {
                                "type": "integer"
                            },
                            "maxLength": {
                                "type": "integer"
                            },
                            "unique": {
                                "type": "boolean"
                            },
                            "pattern": {
                                "type": "string"
                            },
                            "minimum": {
                                "oneOf": [
                                    {
                                        "type": "string"
                                    },
                                    {
                                        "type": "number"
                                    }
                                ]
                            },
                            "maximum": {
                                "oneOf": [
                                    {
                                        "type": "string"
                                    },
                                    {
                                        "type": "number"
                                    }
                                ]
                            }
                        }
                    }
                },
                "required": [
                    "name"
                ]
            }
        },
        "primaryKey": {
            "oneOf": [
                {
                    "type": "string"
                },
                {
                    "type": "array"
                }
            ]
        },
        "foreignKeys": {
            "type": "array",
            "items": {
                "type": "object",
                "required": [
                    "fields",
                    "reference"
                ],
                "properties": {
                    "fields": {
                        "oneOf": [
                            {
                                "type": "string"
                            },
                            {
                                "type": "array"
                            }
                        ]
                    },
                    "reference": {
                        "type": "object",
                        "required": [
                            "resource",
                            "fields"
                        ],
                        "properties": {
                            "resource": {
                                "type": "string"
                            },
                            "fields": {
                                "oneOf": [
                                    {
                                        "type": "string"
                                    },
                                    {
                                        "type": "array"
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    },
    "required": [
        "fields"
    ]
}