This repository contains JSON Schema definitions for EDIFACT messages, segments, composite data elements, and data elements, generated from the EDIFACT D95B standard.
The schemas are organized by EDIFACT version (currently D95B) and type:
edifact-schema/
├── D95B/
│ ├── dataelement/ # Simple data element schemas
│ ├── compositedataelement/ # Composite data element schemas
│ ├── segment/ # Segment schemas
│ └── message/ # Message schemas (e.g., APERAK, INVOIC, etc.)
├── schema.php # PHP generator script
├── composer.json # PHP dependencies
└── README.md # This file
All schemas use https://php-edifact.github.io/edifact-schema/ as the base URL for $id and $ref references. When hosting on GitHub Pages, these schemas can reference each other using relative paths or the full URL.
All schemas follow the JSON Schema Draft 2020-12 specification.
- Data Elements: Simple fields with type, maxLength, and optional enum/oneOf constraints
- Composite Data Elements: Objects containing multiple data elements
- Segments: Objects containing data elements and composite data elements
- Messages: Objects containing segments and segment groups
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "https://php-edifact.github.io/edifact-schema/D95B/segment/ADR.edifact.schema.json"
}{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "https://php-edifact.github.io/edifact-schema/D95B/dataelement/1001.edifact.schema.json"
}import json
import jsonschema
# Load the schema
with open('D95B/message/APERAK.edifact.schema.json') as f:
schema = json.load(f)
# Validate a message
message = {
"UNH": {...},
"BGM": {...},
# ... other segments
}
try:
jsonschema.validate(message, schema)
print("Valid message!")
except jsonschema.ValidationError as e:
print(f"Validation error: {e.message}")const Ajv = require('ajv');
const schema = require('./D95B/message/APERAK.edifact.schema.json');
const ajv = new Ajv({ schemaId: 'auto' });
ajv.addSchema(schema);
const message = { /* your message data */ };
const valid = ajv.validate('https://php-edifact.github.io/edifact-schema/D95B/message/APERAK.edifact.schema.json', message);
if (!valid) {
console.log('Validation errors:', ajv.errors);
}To regenerate the schemas from EDIFACT XML definitions:
cd edifact-schema
composer install
php schema.php # Generate D95B (default)
php schema.php D96A # Generate specific version
php schema.php all # Generate all versions (D00A-D99B)This will create/update the D95B directory with all schema files.
Some message schemas contain references to non-existent UNH component files (e.g., unh1.edifact.schema.json, unh2.edifact.schema.json). This is because the UNH segment uses semantic names rather than numeric data element IDs in the source XML.
Some segment properties reference composite data elements that may not exist in the generated schema files.
- Push this repository to GitHub
- Go to Repository Settings > Pages
- Select the
mainbranch as the source - The schemas will be available at
https://php-edifact.github.io/edifact-schema/
Currently supported:
- D95B - UN/EDIFACT Directory D95B (December 1995)
This project is provided as-is for EDIFACT to JSON Schema conversion purposes.
- JSON Schema Specification
- EDIFACT Standard
- php-edifact - PHP EDIFACT mapping library