A comprehensive Python tool for validating JSON data against JSON schemas and analyzing connections between hardware components in the JSON files.
- JSON Schema Validation: Validates JSON data against Draft4 JSON schemas with detailed error reporting
- Component Connection Analysis: Verifies connections between devices, connectors, and buses
- Tree Structure Rendering: Builds and visualizes component hierarchies
- Duplicate Detection: Identifies and logs duplicate identifiers in component data
- Comprehensive Logging: Structured logs with optional file output for troubleshooting
- Python 3.7 or higher
- Clone the repository:
git clone https://github.com/opencomputeproject/OCP-SVR-MHS-M-PNP_JSON_Val_Tool.git json-validator
cd json-validator- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\Activate.ps1- Install dependencies:
pip install -r requirements.txtValidate JSON data against a schema:
python main.py <data.json> <schema.json>Generate and save a visual tree of components:
python main.py <data.json> <schema.json> --tree-to-fileThis creates a tree.txt file showing the hierarchical structure of components.
Check if the schema itself is valid:
python main.py <data.json> <schema.json> --validate-schema-onlySkip schema validation and only validate data against schema:
python main.py <data.json> <schema.json> --validate-data-onlySave detailed validation logs:
python main.py <data.json> <schema.json> --log-file validation.logEnable debug-level logging:
python main.py <data.json> <schema.json> --verboseShow only errors:
python main.py <data.json> <schema.json> --ignore-warningspython main.py <data.json> <schema.json> \
--tree-to-file \
--log-file results.log \
--verboseFull validation + tree + logs:
python main.py <data.json> <schema.json> --tree-to-file --log-file validation.logSchema only: --validate-schema-only
Data only: --validate-data-only
Debug output: --verbose
Errors only: --ignore-warnings
Core components:
- JSONValidator: Schema + instance validation
- JSONNavigator: Tree building and connectivity checks
- Registries (Device, Connector, Bus): Indexed lookup; duplicates skipped
- Components: Connection models; semantics for devices, connectors, buses
Tree-building flow: Parse root (HPM/standard) → find SCIs → process buses → explore hubs/muxes → resolve endpoints → join FPGAs/SOCs.
Validation: Schema first, then data against schema, then cross-references (devices/connectors linked to valid buses).
The tool reports validation results via logging (default level: INFO):
2026-04-15 21:20:10 - INFO - Schema is valid.
2026-04-15 21:20:10 - INFO - Data against the schema is valid.
2026-04-15 21:20:11 - INFO - Validation finished with 0 ERROR(S) and 0 WARNING(S).
When using --tree-to-file, a hierarchical tree structure is generated:
HPM
├── SCI-001
│ ├── BUS-001
│ │ ├── CONNECTOR-001
│ │ └── DEVICE-001
│ └── PCIE-001
│ └── ...
└── FPGA-DEVICE
└── BUS-002
Logs include component validation, connection verification, and warnings:
2026-04-02 10:15:30 - INFO - Starting JSON Validation and Navigation Tool.
2026-04-02 10:15:30 - DEBUG - Schema validation completed successfully.
2026-04-02 10:15:31 - WARNING - Duplicate device identifier found: DEVICE-001. Skipping duplicate.
2026-04-02 10:15:31 - ERROR - [DEVICE] DEVICE-002 is not connected to its parent: BUS-001
Use --verbose to enable DEBUG messages (including file-loading internals).
The tool validates:
- Schema Compliance: Ensures data matches the provided JSON schema
- Component Identifiers: Verifies all components have unique identifiers
- Connection Validity: Confirms devices/connectors reference valid buses
- Bus Connectivity: Validates bus trees and their connected components
- FPGA Connections: Special handling for FPGA devices and their bus connections
- Endpoint Verification: Ensures all endpoints in trees are properly defined
jsonschema>=4.17.3: JSON Schema validationanytree>=2.12.1: Tree structure representation
See requirements.txt for exact versions.
Sample JSON files and schema files in this repository come from the Open Compute Project (OCP) M-PnP release materials:
- Source page: https://www.opencompute.org/w/index.php?title=Server/MHS/DC-MHS-Specs-and-Designs
- Package: M-PnP v0.5 Release Package (published 2025-09-26)
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please ensure:
- Code follows PEP 8 style guidelines
- All changes include appropriate logging
- Error messages include context tags (e.g.,
[FILE],[BUS],[CONNECTOR]) - New features include validation and error handling