json-tokenizer: Structure-Aware Tokenization for JSON
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.
from json_tokenizer import JSONTokenizer
tok = JSONTokenizer(bpe_vocab_size=4096, max_key_vocab=512)
tok.train_from_json_files(["your_data.jsonl"])
tok.save("./my_tokenizer")
# Convert to HF formatfrom json_tokenizer.hf_compat import JSONPreTrainedTokenizer
hf_tok = JSONPreTrainedTokenizer.from_json_tokenizer(tok)
hf_tok.save_pretrained("./my_hf_tokenizer")
Where It Wins / Where It Loses
Scenario
json-tokenizer
cl100k_base
GeoJSON (schema-repetitive)
+7.8% savings
baseline
Telemetry logs
+5.5% savings
baseline
Batch JSON arrays
+9.3% savings
baseline
Config objects
+12.3% savings
baseline
Prose-heavy JSON (Alpaca)
-26.2%
wins
K8s manifests (deep nesting)
break-even
break-even
Best for:
API responses, observability logs, function calling, structured outputs
Not for:
Prose-heavy JSON, general-purpose text
Citation
@software{maio2026jsontokenizer,
author = {Maio, Anthony},
title = {Structure-Aware Tokenization for {JSON}: Exploiting Schema Repetition for Compact Token Sequences with a 90x Smaller Vocabulary},
year = {2026},
url = {https://github.com/anthony-maio/json-tokenizer},
doi = {10.5281/zenodo.18879110},
version = {0.2.0},
license = {MIT}
}
License
MIT
Runs of anthonym21 json-tokenizer-structured on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About json-tokenizer-structured huggingface.co Model
More json-tokenizer-structured license Visit here:
json-tokenizer-structured huggingface.co is an AI model on huggingface.co that provides json-tokenizer-structured's model effect (), which can be used instantly with this anthonym21 json-tokenizer-structured model. huggingface.co supports a free trial of the json-tokenizer-structured model, and also provides paid use of the json-tokenizer-structured. Support call json-tokenizer-structured model through api, including Node.js, Python, http.
json-tokenizer-structured huggingface.co is an online trial and call api platform, which integrates json-tokenizer-structured's modeling effects, including api services, and provides a free online trial of json-tokenizer-structured, you can try json-tokenizer-structured online for free by clicking the link below.
anthonym21 json-tokenizer-structured online free url in huggingface.co:
json-tokenizer-structured is an open source model from GitHub that offers a free installation service, and any user can find json-tokenizer-structured on GitHub to install. At the same time, huggingface.co provides the effect of json-tokenizer-structured install, users can directly use json-tokenizer-structured installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
json-tokenizer-structured install url in huggingface.co: