# condense-json 1.0 发布：用替换语法压缩 JSON 重复字符串

- 来源：Simon Willison 博客
- 发布时间：2026-08-03 06:19
- AIHOT 分数：46
- AIHOT 链接：https://aihot.virxact.com/items/cmscgh8d306tzroeu06uk6qgo
- 原文链接：https://simonwillison.net/2026/Aug/2/condense-json

## AI 摘要

Simon Willison 发布 condense-json 1.0，这个 Python 库可将 JSON 中与替换对象匹配的字符串或子串替换为特殊 `{"$r": ...}` 语法，并可用 `uncondense_json` 还原。作者用它压缩 LLM 生成的 SQLite 日志中的重复数据以节省空间。

## 正文

Release: condense-json 1.0

I'm trying to get braver at releasing 1.0 versions. This little library is a year and a half old now - I've applied some sensible and non-disruptive fixes and shipped the big 1.0 for it.

Here's an example of what it can do, lifted from the README:

{ "foo": { "bar": { "string": "This is a string with foxes in it", "nested": { "more": ["Here is a string", "another with foxes in it too"] } } } }

Combine that with a replacements object:

{"1": "with foxes in it"}

And condense_json(input_json, replacements) produces the following:

{ "foo": { "bar": { "string": {"$r": ["This is a string ", {"$": "1"}]}, "nested": { "more": ["Here is a string", {"$r": ["another ", {"$": "1"}, " too"]}] } } } }

It scans for strings or substrings that are present in that replacements object and replaces those with a special {"$r": ...} syntax in the output.

You can reverse the effect with uncondense_json(condensed, replacements).

The idea is to make it easier to store JSON that includes duplicated data from other related structures. I use it to save space in the SQLite logs generated by LLM - see PR #1586 for the latest iteration of that.

Tags: json, projects, python, llm
