Skip to main content

Red → Green: UTF-8 JSONL Validation Workshop

CI PyPI Python 3.10+ License: MIT

A small, dependency-free, offline Python workshop that shows why a byte limit must count UTF-8 bytes rather than Unicode characters, using a strict JSONL validator and an automated red → green regression demo. Türkçe özet aşağıda.

At a glance

  • 🚀 is 1 Unicode character but 4 UTF-8 bytes; a limit declared in bytes must check the latter.
  • jsonl_utf8_guard.py reads JSONL with a bounded buffer, validates UTF-8 strictly, rejects duplicate object keys (including nested and Unicode-escaped ones) and prints only the number of JSON objects, never input records.
  • red_green_demo.py proves the regression test catches the bug: it fails on a deliberately broken copy and passes on the real code.
  • verify_release.py checks every source file, or a ZIP without extracting it, against SHA256SUMS.
  • Python 3.10+ only: no network, packages, cloud services, API keys or credentials.

Quick start

From PyPI:

pip install jsonl-utf8-guard
jsonl-utf8-guard --input sample_events.jsonl

From a clone, with nothing installed:

py -3 jsonl_utf8_guard.py --input sample_events.jsonl
py -3 -m unittest discover -p "test_*.py" -v
py -3 red_green_demo.py
py -3 verify_release.py

Details

Red → green demo

red_green_demo.py creates an intentionally buggy copy in a temporary directory, confirms that the targeted regression test fails there, then reruns the same test against the corrected code. It checks with SHA-256 that the working source was never modified. You can also compare the two implementations by hand in a disposable copy.

Verifying the files

py -3 verify_release.py validates every expected file against SHA256SUMS. It rejects malformed, duplicate, unexpected or path-traversal manifest entries, detects changed or missing files, and never prints file contents. .gitattributes keeps the manifest-verified bytes identical on Windows, macOS and Linux.

A workshop ZIP can be checked without extraction:

py -3 verify_release.py --archive "path\to\offline-jsonl-workshop.zip"

This checks the exact expected members, rejects duplicate, unsafe, symlinked, encrypted, oversized or missing entries, and verifies source bytes against the bundled SHA256SUMS without running archive contents.

To authenticate a download, also check the full ZIP hash obtained from a trusted independent channel, either directly or from a sidecar file:

py -3 verify_release.py --archive "path\to\offline-jsonl-workshop.zip" --expected-archive-sha256 "<trusted_64_character_lowercase_sha256>"
py -3 verify_release.py --archive "offline-jsonl-workshop.zip" --trusted-sha256-file "offline-jsonl-workshop.zip.sha256"

The tool hashes the exact bytes it then parses and rejects malformed or mismatched hashes; --archive is required. The sidecar must hold a single LF- or CRLF-terminated record in the format <64 lowercase hex digits> workshop.zip with a matching ZIP filename; oversized, malformed or symlinked sidecars are rejected. The two options cannot be combined.

Reporting every invalid line

By default the validator stops at the first bad record, which is the right thing for a quick check. For a large export, --report-all keeps scanning and prints one bounded JSON summary instead:

py -3 jsonl_utf8_guard.py --input multi.jsonl --report-all
# {"status": "invalid", "records": 2, "errors": [{"line": 2, "reason": "invalid JSON"}, {"line": 4, "reason": "expected a JSON object, got an array"}], "truncated": false, "max_bytes": 65536}

Exit code 2 still means invalid input and 0 means valid input; records counts the valid objects seen, so it stays exact even when lines fail. At most 100 errors are reported and "truncated": true marks a longer list. A line over --max-bytes is still rejected before its bytes are decoded: the rest of that line is drained in fixed-size chunks so the following lines can be checked without ever decoding or printing the record. Reasons carry a line number and a cause only, never record content or key names.

Offline package

A separate release builder in the original development workspace (prepare_workshop_release.py, not needed to use the archive) packages the workshop from an explicit allowlist: this README, the bilingual runbook (WORKSHOP_RUNBOOK_TR_EN.md), the sample, the license, three scripts, three test modules and SHA256SUMS, without backups, credentials or local handoff files. Rebuilding from the same source bytes gives the same ZIP hash, and a SHA-256 sidecar is written beside the ZIP. After extracting it into its own directory:

py -3 -m unittest discover -p "test_*.py" -q
py -3 verify_release.py
py -3 red_green_demo.py
py -3 jsonl_utf8_guard.py --input sample_events.jsonl

AI-assisted workflow

A 5-minute tutorial (TR/EN) walks through the Claude Code workflow used for the --version flag (#8): AGENTS.md rules, test first, SHA256SUMS update and a PR with an AI-assistance section.

Limitations

  • Educational, not a production parser. It does no network requests, never executes or logs input JSON, and never modifies input, but it is not a general-purpose JSON library.
  • Integrity is not authenticity. The bundled SHA256SUMS proves only that a ZIP is self-consistent; an attacker who replaces the files and the manifest gets another consistent ZIP. A hash or sidecar downloaded from the same untrusted location proves nothing about the publisher, and no release signature or trusted checksum channel is provided.
  • No published workshop ZIP. The offline package is built locally; it is not attached to a GitHub release.
  • Independent material. This is not an official Anthropic product, partnership, certification or Anthropic-maintained repository, and no workshop, attendance, sponsorship or program acceptance is claimed.

Contributors

Thanks to everyone who has improved this workshop:

  • @P1LOTRX: clear errors for a UTF-8 BOM (#31) and for bare carriage returns (#32), released in v0.2.0.
  • @rise11hx-cmyk: --max-bytes rejected as a usage error (#41), named messages for duplicate keys and non-finite numbers (#40), and --report-all (#33), released in v0.3.0.
  • @jwalith4418-Mj: non-object records name their JSON type without echoing the value (#47), released in v0.3.0.

Want to join them? Issues labelled good first issue have a reproduction and a definition of done, and questions are welcome in Discussions. See CONTRIBUTING.md.

Türkçe

Bayt sınırının neden Unicode karakter sayısıyla değil UTF-8 bayt sayısıyla kontrol edilmesi gerektiğini gösteren, bağımlılıksız ve çevrimdışı bir Python atölyesi.

  • 🚀 emojisi 1 Unicode karakteridir ama UTF-8 ile 4 bayt yer kaplar. Boyut sınırı bayt cinsinden ilan edildiyse gerçek bayt sayısı kontrol edilmelidir.
  • Doğrulayıcı UTF-8'i katı biçimde denetler, iç içe ve Unicode escape ile yazılmış olanlar dahil tekrarlanan anahtarları reddeder (böylece son değer öncekinin üzerine sessizce yazılmaz) ve yalnızca nesne sayısını yazdırır; dosya içeriğini veya hassas anahtar adlarını paylaşmaz.
  • red_green_demo.py hatalı sürümü geçici bir dizinde oluşturur, regresyon testinin orada başarısız, doğru kodda başarılı olduğunu otomatik doğrular ve kaynak dosyanın değişmediğini SHA-256 ile kontrol eder.
  • Gereksinimler: Python 3.10+; hesap, bulut, API anahtarı veya ek paket gerekmez.

Kurulum ve çalıştırma:

pip install jsonl-utf8-guard
jsonl-utf8-guard --input sample_events.jsonl

Ya da hiçbir şey kurmadan klonlanmış depodan:

py -3 jsonl_utf8_guard.py --input sample_events.jsonl
py -3 -m unittest discover -p "test_*.py" -v
py -3 red_green_demo.py

Dosyaları doğrulama. Depoyu klonladıktan veya ZIP paketini çıkardıktan sonra py -3 verify_release.py çalıştırın. Araç tüm kaynak dosyalarını SHA256SUMS ile karşılaştırır; değiştirilmiş veya eksik dosyaları, hatalı veya yinelenmiş manifest kayıtlarını ve klasör dışına erişim girişimlerini reddeder. ZIP'i açmadan kontrol etmek için --archive "path\to\offline-jsonl-workshop.zip" kullanın; yinelenen, eksik, güvensiz, sembolik bağlantılı ve aşırı büyük kayıtlar reddedilir, ZIP içindeki kod çalıştırılmaz. ZIP'in tam SHA-256 değerini bağımsız ve güvenilir bir kaynaktan aldıysanız --expected-archive-sha256 "<guvenilir_64_karakter_kucuk_harf_sha256>" veya --trusted-sha256-file ile ayrıca kontrol edin; yan dosya Windows CRLF ve Linux LF satır sonlarını destekler.

Tüm hatalı satırları raporlama. Varsayılan olarak doğrulayıcı ilk hatalı kayıtta durur. Büyük bir dışa aktarım için --report-all taramaya devam eder ve tek bir sınırlı JSON özeti yazdırır: {"status": "invalid", "records": 2, "errors": [{"line": 2, "reason": "invalid JSON"}], "truncated": false, "max_bytes": 65536}. Çıkış kodu 2 yine geçersiz giriş, 0 geçerli giriş anlamına gelir; records görülen geçerli nesne sayısıdır. En fazla 100 hata raporlanır ve daha uzun liste "truncated": true ile işaretlenir. --max-bytes sınırını aşan satır yine çözülmeden reddedilir; satırın geri kalanı sabit boyutlu parçalarla tüketilir, böylece sonraki satırlar denetlenebilir ve kayıt içeriği hiçbir zaman yazdırılmaz.

Sınırlamalar. Örnek eğitim amaçlıdır, genel bir üretim ayrıştırıcısı değildir. Paket içindeki SHA256SUMS yalnızca iç tutarlılığı gösterir, yayıncının kimliğini kanıtlamaz; ZIP ile aynı güvenilmeyen kaynaktan gelen hash veya yan dosya da kanıtlamaz. Atölye bağımsız olarak hazırlanmıştır; gerçek etkinlik, katılımcı, sponsorluk veya program kabulü iddiası yoktur.

AI destekli iş akışı: 5 dakikalık öğretici (TR/EN), --version seçeneği (#8) için kullanılan Claude Code iş akışını anlatır: AGENTS.md kuralları, önce test, SHA256SUMS güncellemesi ve AI yardım bölümlü PR.

License

MIT

Metadata

Release files for jsonl-utf8-guard 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonl-utf8-guard 0.3.0
File Size Uploaded Provenance Actions
jsonl_utf8_guard-0.3.0.tar.gz 10.5 kB With provenance Details for jsonl_utf8_guard-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jsonl-utf8-guard 0.3.0
File Interpreter ABI Platform Actions
jsonl_utf8_guard-0.3.0-py3-none-any.whl Python 3 none any Details for jsonl_utf8_guard-0.3.0-py3-none-any.whl

Total release size: 21.2 kB

Release files / jsonl_utf8_guard-0.3.0.tar.gz

Download URL jsonl_utf8_guard-0.3.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e2ef47cb45a59059af4989a872456bd50dad238a8865b9e2dbe8de5317b815f0
BLAKE2b-256 checksum
How to use checksums
0e9ca743e5160b7f84298469ead65ec5b86814662c70d7af4cad8748b995da1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / jsonl_utf8_guard-0.3.0-py3-none-any.whl

Download URL jsonl_utf8_guard-0.3.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b421f9ad9f097b2ffb403bd03996e25c95b4be434ab14a4be251276d7949784c
BLAKE2b-256 checksum
How to use checksums
4bf60f8ff46f5309a50fc779cc4cbcc9ef408ca9b9c9509ef18a0aab1b9d3985
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for jsonl-utf8-guard 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jsonl_utf8_guard-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page