Metadata-Version: 2.4
Name: robotframework-jsonschemavalidation
Version: 0.1.0
Summary: Robot Framework library that validates JSON against a JSON Schema and logs a rich HTML comparison card
Author: heynirinx
License-Expression: MIT
Keywords: robotframework,jsonschema,json-schema,validation,testing,api-testing
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Robot Framework
Classifier: Framework :: Robot Framework :: Library
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
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: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: robotframework>=4.0
Requires-Dist: jsonschema>=3.0
Dynamic: license-file

# robotframework-jsonschemavalidation

A Robot Framework library that validates a JSON object against a JSON Schema and
logs a rich, colour-coded HTML comparison card into `log.html`.

Instead of a bare pass/fail, every validation produces a side-by-side view of the
JSON and the schema, with each key highlighted by status, a summary donut chart,
and a table of concrete issues and suggestions.

## Features

- Validates with [`jsonschema`](https://pypi.org/project/jsonschema/) and fails the test on error
- Side-by-side JSON vs. Schema panels with syntax highlighting
- Per-key highlighting: matched, missing in schema, missing in JSON, type mismatch
- Nested objects and arrays are compared recursively
- Summary donut chart with counts per status
- Collapsible "Issues & Suggestions" table, auto-expanded when validation fails
- Validation timing in milliseconds

## Installation

```
pip install robotframework-jsonschemavalidation
```

## Usage

```robotframework
*** Settings ***
Library    JsonSchemaValidation
Library    RequestsLibrary

*** Test Cases ***
Validate Product Response
    ${resp}=    GET    https://fakestoreapi.com/products/1
    Validate Json Schema    ${resp.json()}    ${CURDIR}/schemas/product.json
```

## Keyword

### `Validate Json Schema`

| Argument | Required | Description |
| --- | --- | --- |
| `json_object` | yes | JSON as a Python dict or list (not a string) |
| `path_to_schema` | yes | Path to the `.json` schema file |
| `encoding` | no | Encoding used to open the schema file, e.g. `utf-8` |

```robotframework
Validate Json Schema    ${json}    ${CURDIR}/schema.json    encoding=utf-8
```

The keyword raises `AssertionError` when the JSON does not match the schema, so
the test fails. The HTML card is logged either way.

If the payload arrives as a string, parse it first:

```robotframework
${json}=    Evaluate    json.loads($raw)    modules=json
Validate Json Schema    ${json}    ${CURDIR}/schema.json
```

To inspect the card without failing the test:

```robotframework
Run Keyword And Ignore Error    Validate Json Schema    ${json}    ${CURDIR}/schema.json
```

## Status legend

| Colour | Status | Meaning |
| --- | --- | --- |
| Green | Matched | Key exists in both and the type matches |
| Amber | Missing in Schema | Key is in the JSON but not declared in the schema |
| Blue | Missing in JSON | Key is declared in the schema but absent from the JSON |
| Red | Type Mismatch | Key exists in both but the value type differs |

## Requirements

- Python 3.8+
- robotframework >= 4.0
- jsonschema >= 3.0

## License

MIT
