gpt4 book ai didi

json - jQuery:递归删除所有与给定模式匹配的键

转载 作者:行者123 更新时间:2023-12-04 14:23:56 26 4
gpt4 key购买 nike

如何递归删除与给定模式匹配的所有键?

我有以下jq配置,但它似乎不起作用:

walk( if (type == "object" and (.[] | test('.*'))) then del(.) else . end)

最佳答案

删除所有与模式匹配的键(例如PATTERN)的健壮方法(针对不同的jq版本)将使用以下惯用法:

with_entries(select( .key | test(PATTERN) | not))

将其插入 walk/1将产生:
walk(if type == "object" then with_entries(select(.key | test(PATTERN) | not)) else . end)

关于json - jQuery:递归删除所有与给定模式匹配的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42635140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com