如何用jq将含命名布尔值的对象转回插件状态数组结构?
Solution for Reversing Flattened Plugin State JSON with jq
- Use
to_entriesto convert the flattened key-value pairs into an array ofkey/valueobjects - Map each entry to the
{name: key, enabled: value}structure - Wrap the resulting array in a
modsobject
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 themodskey to replicate the original JSON structure
内容的提问来源于stack exchange,提问作者jthill
相关产品推荐
相关产品推荐

