Published March 5, 2026 | Version 0.2

Structure-Aware Tokenization for JSON

  • 1. Independent Researcher

Description

We present json-tokenizer, a structure-aware tokenizer that assigns dedicated single tokens to JSON grammar elements, learns a compact key vocabulary from training data, and applies byte-pair encoding (BPE) only to value content. General-purpose subword tokenizers such as cl100k_base treat JSON as flat text, splitting structural syntax characters across multiple tokens and re-encoding identical key names in every object. On schema-repetitive JSON workloads -- including GeoJSON features, observability telemetry, and Kubernetes manifests -- json-tokenizer achieves 5-15% token savings over cl100k_base while using a vocabulary approximately 90x smaller (1,100–4,100 tokens vs. 100,256). Batch encoding of JSON arrays yields savings up to 9.3%. All encodings are lossless: decoded output is byte-identical to the original JSON across 4,200+ test objects. Results are stable across five random seeds (standard deviation <0.01%).

We provide an open-source, zero-dependency Python implementation with HuggingFace PreTrainedTokenizer compatibility, benchmarks on five real-world dataset classes, throughput measurements, a vocabulary size sweep analysis, and an honest comparison showing where general-purpose tokenizers remain superior (prose- heavy JSON).

The tokenizer is designed for LLM structured output pipelines, API response caching, and observability log ingestion, where schema repetition dominates and token budgets directly impact cost and latency.

Files

00_Structure-Aware_Tokenization_for_JSON-Maio,A-(2026).pdf

Files (1.6 MB)

Name Size
md5:7c5e061284905eed46ec6a816080c327
897.5 kB Preview Download
md5:6b538793b41d207ab6076af72da53dd9
49.8 kB Download
md5:e098b67d0232e50b3bfce508e0037bde
1.4 kB Download
md5:10dd9f50df0ba12bd106ec5cc539baa9
71.0 kB Preview Download
md5:b0bba91cc2f17b0801acee4a128c0ca6
110.4 kB Preview Download
md5:d81210c74aecd59268678cc9c0254b5c
131.9 kB Preview Download
md5:c800ca9b71f356f195b92e7b208305b1
93.9 kB Preview Download
md5:62c21eca09c092da6c917225bad8e4dd
83.0 kB Preview Download
md5:054c3d489503815ff3a2da56ccef97e8
124.1 kB Preview Download
md5:82e909cda94b62a8e6a3914e7dc80640
11.7 kB Download

Additional details

Additional titles

Subtitle (English)
Exploiting Schema Repetition for Compact Token Sequences with a 90× Smaller Vocabular

Identifiers

Other
json-tokenizer-structured

Software

Repository URL
https://github.com/anthony-maio/json-tokenizer
Programming language
Python
Development Status
Active