You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用jq将含命名布尔值的对象转回插件状态数组结构?

Solution for Reversing Flattened Plugin State JSON with jq
  • Use to_entries to convert the flattened key-value pairs into an array of key/value objects
  • Map each entry to the {name: key, enabled: value} structure
  • Wrap the resulting array in a mods object

The jq command to perform the reverse conversion is:

{ mods: [ to_entries[] | { name: .key, enabled: .value } ] }

Example Execution

Flattened Input:

{
  "somename": true,
  "someothername": false
}

Command Output:

{
  "mods": [
    {
      "name": "somename",
      "enabled": true
    },
    {
      "name": "someothername",
      "enabled": false
    }
  ]
}

Breakdown of the Command

  • to_entries: Converts the top-level object into an array of entries like [{ "key": "somename", "value": true }, ...]
  • to_entries[]: Iterates over each entry in the array
  • { name: .key, enabled: .value }: Reshapes each entry into the required object format matching the original structure
  • { mods: [...] }: Wraps the transformed array in the mods key to replicate the original JSON structure

内容的提问来源于stack exchange,提问作者jthill

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 23:10:12