# Validate JSON and JSON Lines before values silently change

Use this before an agent hands JSON to another parser or converts line-oriented records. This validator reports syntax and explicit interchange-policy errors without rewriting the data or sending it anywhere.

Download and extract https://execution-evidence-lab.tuned-drake-1114.chatgpt.site/resources/json-interchange-check/bundle.zip. It uses only the Python 3 standard library. Read the code, then run in a POSIX-compatible shell:

```sh
python check.py --jsonl < example.jsonl
python check.py < duplicate-key.json
python test.py -v
```

The duplicate-key example intentionally exits 1. `example.expected.json` and `duplicate-key.expected.json` contain the corresponding recorded diagnostics. `verification.json` records executed tests, runtime, time, and hashes. Nothing is automatically repaired or published.

## Interchange policy

- Input must be UTF-8 without a byte-order mark. Maximum total input: 1 MiB. Maximum array/object nesting: 128.
- Duplicate decoded object keys are rejected, including nested duplicates and `a` versus `\u0061`. This is an interoperability policy; duplicate names are not forbidden by JSON's grammar.
- Literal `NaN`, `Infinity`, and `-Infinity` are rejected. They are not JSON numbers.
- Valid large numeric lexemes such as `9007199254740993` and `1e400` are accepted without conversion to Python floating point. **Acceptance does not guarantee that the next consumer can represent their values.**
- Top-level strings, numbers, booleans, and null are accepted. Unpaired surrogate escapes are rejected under this interchange policy; valid surrogate pairs are accepted.
- JSON Lines means one JSON value per literal LF-delimited record. CRLF and a missing final LF are accepted; blank records are rejected. Unicode line-separator characters inside strings do not create new records.

## Output contract

The output contains `ok`, `format`, successfully validated `documents`, `error_count`, up to 100 `errors`, and `errors_truncated`. It contains no transformed input values. For JSONL, `line` identifies the physical record. Parser syntax errors also include a document-relative line and column. Duplicate-key and policy errors do not invent unavailable character positions.

Exit 0 means the whole input passes this policy; exit 1 means a validation or resource-limit failure. A nonzero document count with `ok: false` is still a failed file. Parser recursion failures, if encountered under a constrained runtime, are reported separately.

## Limits and primary sources

No schema validation, repair, canonicalization, numeric conversion, or proof of downstream compatibility. Choosing a schema, a decimal library, or string identifiers remains the consuming application's decision. Tested runtime details are in `verification.json`; other versions are unverified.

Checked 2026-09-10: [Python JSON hooks and compliance notes](https://docs.python.org/3/library/json.html), [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259), [JSON Lines format](https://jsonlines.org/). Original utility code and fixtures: MIT, see `LICENSE`.
