Delete objects and arrays with jq which match a key

后端 未结 1 1076
时光取名叫无心
时光取名叫无心 2021-01-12 01:41

I have a JSON with the following content:

{
  \"data\": [
    {
      \"name\": \"Test\",
      \"program\": {
        \"publicAccess\": \"--------\",
               


        
相关标签:
1条回答
  • 2021-01-12 02:16

    Your problem is when type == "array" is true . will be an array so .userGroupAccesses won't work. What you want to do is focus on the case when . is an object. In your call to walk you only need to check for type == "object" and then remove the members you don't want. e.g.

    walk(if type == "object" then del(.publicAccess, .userGroupAccesses) else . end)
    

    Try it online at jqplay.org

    You can also solve this without walk by using Recursive Descent .. e.g.

    del(.. | .publicAccess?, .userGroupAccesses?)
    

    Try it online at jqplay.org

    0 讨论(0)
提交回复
热议问题