Skip to content

opencomputeproject/OCP-SVR-MHS-M-PNP_JSON_Val_Tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Validator for Hardware Components

A comprehensive Python tool for validating JSON data against JSON schemas and analyzing connections between hardware components in the JSON files.

Features

  • 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

Installation

Prerequisites

  • Python 3.7 or higher

Setup

  1. Clone the repository:
git clone https://github.com/opencomputeproject/OCP-SVR-MHS-M-PNP_JSON_Val_Tool.git json-validator
cd json-validator
  1. Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\Activate.ps1
  1. Install dependencies:
pip install -r requirements.txt

Usage

Basic Validation

Validate JSON data against a schema:

python main.py <data.json> <schema.json>

Print Component Tree

Generate and save a visual tree of components:

python main.py <data.json> <schema.json> --tree-to-file

This creates a tree.txt file showing the hierarchical structure of components.

Validate Schema Only

Check if the schema itself is valid:

python main.py <data.json> <schema.json> --validate-schema-only

Validate Data Only

Skip schema validation and only validate data against schema:

python main.py <data.json> <schema.json> --validate-data-only

Output Logs to File

Save detailed validation logs:

python main.py <data.json> <schema.json> --log-file validation.log

Increase Verbosity

Enable debug-level logging:

python main.py <data.json> <schema.json> --verbose

Suppress Warnings

Show only errors:

python main.py <data.json> <schema.json> --ignore-warnings

Full Example

python main.py <data.json> <schema.json> \
  --tree-to-file \
  --log-file results.log \
  --verbose

Workflows

Full validation + tree + logs:

python main.py <data.json> <schema.json> --tree-to-file --log-file validation.log

Schema only: --validate-schema-only
Data only: --validate-data-only
Debug output: --verbose
Errors only: --ignore-warnings

Architecture

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).

Output

Validation Results

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).

Tree Output (tree.txt)

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

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).

Validation Rules

The tool validates:

  1. Schema Compliance: Ensures data matches the provided JSON schema
  2. Component Identifiers: Verifies all components have unique identifiers
  3. Connection Validity: Confirms devices/connectors reference valid buses
  4. Bus Connectivity: Validates bus trees and their connected components
  5. FPGA Connections: Special handling for FPGA devices and their bus connections
  6. Endpoint Verification: Ensures all endpoints in trees are properly defined

Requirements

  • jsonschema>=4.17.3: JSON Schema validation
  • anytree>=2.12.1: Tree structure representation

See requirements.txt for exact versions.

Sample Data Provenance

Sample JSON files and schema files in this repository come from the Open Compute Project (OCP) M-PnP release materials:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

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

About

Simple JSON validation tool that validates hardware component configuration files against schemas and analyzes the interconnections between system components like buses, connectors, and devices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages