Simon Willison · 博客

condense-json 1.0

condense-json 1.0

二〇二六年八月二十六日 · 英文原文

condense-json 1.0 发布,该小型库历经一年半开发,应用无破坏性修复后推出正式版本。其功能为扫描 JSON 中的字符串或子字符串,若与 replacements 对象匹配,则替换为特殊 `{"$r": ...}` 语法,并可通过 `uncondense_json` 逆转。旨在简化存储含重复数据的 JSON,作者用于节省 LLM 生成的 SQLite 日志空间,相关迭代见 PR #1586。

发布:condense-json 1.0

我正在尝试更勇敢地发布 1.0 版本。这个小型库已经有一年半的历史了——我应用了一些合理且无破坏性的修复,并为其发布了重要的 1.0 版本。以下是一个示例,展示了它的功能,摘自 README:

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

将其与一个 replacements 对象结合:

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

然后 condense_json(input_json, replacements) 会生成以下结果:

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

它会扫描字符串或子字符串,如果这些内容存在于 replacements 对象中,则将其替换为输出中的特殊 {"$r": ...} 语法。你可以通过 uncondense_json(condensed, replacements) 来逆转这一效果。其目的是让存储包含来自其他相关结构的重复数据的 JSON 变得更加容易。我用它来节省 LLM 生成的 SQLite 日志空间——参见 PR #1586 了解最新迭代。

标签:json、projects、python、llm

译自 Simon Willison · 博客 · 录于 二〇二六年八月二十六日