{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://integra.priyaio.com/schemas/json-output/v1.0.0",
    "title": "IOSetu AL3 JSON Output Format",
    "description": "Schema for AL3 parsed output in JSON and NDJSON formats. See schemas.md for integration guide and examples.",
    "version": "1.0.0",
    "type": "object",
    "required": [
        "data"
    ],
    "properties": {
        "data": {
            "type": "object",
            "required": [
                "policies"
            ],
            "properties": {
                "policies": {
                    "type": "array",
                    "description": "Array of parsed AL3 groups. For NDJSON format, each line contains one Group object (without the 'policies' wrapper).",
                    "items": {
                        "$ref": "#/$defs/Group"
                    }
                },
                "metadata": {
                    "type": "object",
                    "description": "Optional parsing metadata (JSON format only, not in NDJSON).",
                    "properties": {
                        "parseTime": {
                            "type": "string",
                            "format": "date-time",
                            "description": "ISO 8601 timestamp of parsing"
                        },
                        "inputSize": {
                            "type": "integer",
                            "description": "Input file size in bytes"
                        },
                        "groupCount": {
                            "type": "integer",
                            "description": "Total number of groups parsed"
                        }
                    }
                }
            }
        },
        "processingTime": {
            "type": "string",
            "description": "Server processing duration (e.g. 1.2ms)."
        }
    },
    "$defs": {
        "Group": {
            "type": "object",
            "description": "Represents a parsed AL3 group with data elements and optional child groups.",
            "required": [
                "code",
                "level"
            ],
            "properties": {
                "code": {
                    "type": "string",
                    "pattern": "^[0-9][A-Z]{3}$",
                    "description": "4-character AL3 group code (e.g., '5BPI', '2TRG')"
                },
                "level": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9,
                    "description": "Hierarchy level: 0-3 for control groups, 5-9 for data groups"
                },
                "processingLevel": {
                    "type": "string",
                    "description": "Processing level code (e.g., 'B1', '00')"
                },
                "iteration": {
                    "type": "string",
                    "pattern": "^[0-9]{4}$",
                    "description": "Group iteration number (4-digit string, e.g. '0001') for repeating groups"
                },
                "dataElements": {
                    "type": "object",
                    "description": "Data element key-value pairs. Field naming patterns: base field (formatted), ' - Raw' (original AL3), ' - Formatted' (decoded codes), personal names expand with ' - FirstName', ' - LastName', etc. See schemas.md for details.",
                    "additionalProperties": true
                },
                "children": {
                    "type": "array",
                    "description": "Nested child groups in AL3 hierarchy",
                    "items": {
                        "$ref": "#/$defs/Group"
                    }
                }
            }
        }
    }
}