Metadata-Version: 2.2
Name: jsonstat-validator
Version: 0.1.0
Summary: A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
Home-page: https://github.com/ahmed-hassan19/jsonstat-validator
Author: Ahmed Hassan
Author-email: Ahmed Hassan <ahmedhassan.ahmed@fao.org>
License: # MIT License
        
        Copyright (c) 2025 JSON-stat Validator Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/ahmed-hassan19/jsonstat-validator
Project-URL: Bug Tracker, https://github.com/ahmed-hassan19/jsonstat-validator/issues
Project-URL: Documentation, https://github.com/ahmed-hassan19/jsonstat-validator#readme
Keywords: json-stat,validator,json,data-engineering,pydantic,python,fao
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic<3.0.0,>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=8.1.1; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: requires-python

# JSON-stat Validator

[![PyPI version](https://badge.fury.io/py/jsonstat-validator.svg)](https://badge.fury.io/py/jsonstat-validator)
[![Python Version](https://img.shields.io/pypi/pyversions/jsonstat-validator.svg)](https://pypi.org/project/jsonstat-validator/)
[![License](https://img.shields.io/github/license/ahmed-hassan19/jsonstat-validator.svg)](https://github.com/ahmed-hassan19/jsonstat-validator/blob/main/LICENSE)

A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.

JSON-stat is a simple lightweight format for data interchange. It is a JSON format for data dissemination that allows the representation of statistical data in a way that is both simple and convenient for data processing. With this validator, you can ensure your data conforms to the official [JSON-stat 2.0 specification](https://json-stat.org/full/).

## Installation

```bash
pip install jsonstat-validator
```

## Usage

### Basic Validation

```python
import json
from jsonstat_validator import validate_jsonstat

# Load your JSON-stat data
with open("data.json", "r") as f:
    data = json.load(f)

# Validate the data
try:
    result = validate_jsonstat(data)
    print("Validation successful!")
except ValueError as e:
    print(f"Validation failed: {e}")
```

### Example JSON-stat Dataset

Here's a simplified example of a JSON-stat dataset representing unemployment data:

```json
{
  "version": "2.0",
  "class": "dataset",
  "label": "Unemployment rate sample",
  "source": "Sample data",
  "updated": "2023-01-15",
  "id": ["indicator", "area", "year"],
  "size": [1, 3, 2],
  "value": [5.8, 6.2, 7.1, 7.5, 4.2, 4.9],
  "role": {
    "time": ["year"],
    "geo": ["area"],
    "metric": ["indicator"]
  },
  "dimension": {
    "indicator": {
      "label": "Economic indicator",
      "category": {
        "label": {
          "UNR": "unemployment rate"
        },
        "unit": {
          "UNR": {
            "symbol": "%",
            "decimals": 1
          }
        }
      }
    },
    "year": {
      "label": "Year",
      "category": {
        "index": ["2020", "2021"]
      }
    },
    "area": {
      "label": "Country",
      "category": {
        "index": ["US", "JP", "EU"],
        "label": {
          "US": "United States",
          "JP": "Japan",
          "EU": "European Union"
        }
      }
    }
  }
}
```

## Features

- Validates JSON-stat data against the [full 2.0 specification](https://json-stat.org/full).
- Provides models for all major JSON-stat responses: **Dataset**, **Dimension**, **Collection**.
- Built on Pydantic for robust type validation and error messages.
- Provides tests against the [official JSON-stat samples](https://json-stat.org/samples/collection.json) as well as custom fine-grained tests.

## Testing

The validator has been thoroughly tested with all official JSON-stat samples from the [JSON-stat website](https://json-stat.org/samples/).

To run tests:

First, install the development dependencies:

```bash
pip install jsonstat-validator[dev]
```

Then run the tests:

```bash
pytest
```

To run a specific test file (e.g. test official samples only):

```bash
pytest tests/test_official_samples.py
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/new-feature`)
3. Commit your changes (`git commit -m 'Add some new feature'`)
4. Push to the branch (`git push origin feature/new-feature`)
5. Open a Pull Request

## Credits

This package is maintained by Ahmed Hassan ([@ahmed-hassan19](https://github.com/ahmed-hassan19)) and was created for use at the Food and Agriculture Organization (FAO) of the United Nations.

The JSON-stat format was created by [Xavier Badosa](https://www.linkedin.com/in/badosa).
