Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 582

Eliminate items from multiple element arrays based on partial matches to another array

$
0
0

Given the JSON below, I am struggling for a jq query that will eliminate any items in places[].fThings[] or places.sThings[] that are not a partial string match to any of the strings found in toDo[]. It should be noted not all places will have fThings or sThings present. While it most likely be one or the other, both or neither could be present.

The output should be the same as the input with the non-matching *Things items filtered out. Empty arrays are fine to return.

I've tried a great many combinations of map(select(any(index(...)))) as well as contains but I'm tripping over my own feet with Cannot index or Cannot iterate errors and fear I have missed something obvious.

{"places": [    {"location": "wapc1","type": "pcs,cstrl,refdoc","fGroup": "cert-apc-1","fThings": ["pcs_app#2.1#bp","pcs_app#2.0#bp","pcs_app#2.1#bp","pcs_app#2.1#cc","pcs_app#2.1#ex_acct","pcs_app#2.1#repr"      ]    },    {"location": "wapc2","type": "pcs,cstrl","fGroup": "cert-apc-2","fThings": ["pcs_app#2.1#mts","pcs_app#2.1#mts","pcs_app#2.1#mta","pcs_app#2.1#mtr","pcs_app#2.1#mop","pcs_app#2.1#mor","pcs_app#2.1#mov"      ]    },    {"location": "wapc3","type": "pcs,prx,cstrl","fGroup": "cert-apc-3","fThings": ["pcs_app#2.1#d2c","pcs_app#2.1#ci","pcs_app#2.1#co","pcs_app#2.1#gr","pcs_app#2.1#repr","pcs_app#2.1#refr","pcs_app#2.1#gf","pcs_app#2.1#dq"      ],"aThings": ["prx"      ]    },    {"location": "wapc4","type": "pcs,prx,cstrl","fGroup": "cert-apc-4","fThings": ["pcs_app#2.1#mtr","pcs_app#2.1#mtstat","pcs_app#2.1#mop"      ],"aThings": ["prx"      ]    },    {"location": "wwc1","type": "bsrv","sGroup": ["cert-bs-1"      ],"sThings": ["ci_svc#1.35.0","config_svc#1","erec_svc#1.27","hm_svc#1.34.0","ri_svc#1.0.0"      ]    },    {"location": "wwc2","type": "bsrv","sGroup": ["cert-bs-2"      ],"sThings": ["erec_svc#1.27","profile_svc#1.7","mor_svc#1.33.0","mta_svc#1.31.0","mtr_svc#1.39.0","mtstat_svc#1.35.0","ri_svc#1.0.0"      ]    },    {"location": "wwc3","type": "bsrv,r-bsrv","sGroup": ["cert-bs-3","cert-rs"      ],"sThings": ["co_svc#1.36.0","d2c_svc#1.34.0","erec_svc#1.27","gr_svc#1.19.0","profile_svc#1.7","config_svc#1"      ]    },    {"location": "wwc4","type": "bsrv,r-bsrv","sGroup": ["cert-bs-4","cert-rs"      ],"sThings": ["erec_svc#1.27","profile_svc#1.7","mtstat_svc#1.35.0","config_svc#1","bp_svc#1.46"      ]    }  ],"toDo": ["bp_svc#1.46##1.46.0-2410.0-03","config_svc#1##1.12-2410.0-05","erec_svc#1.27##1.27-2410.0-03","pcs_app#2.1#bp##2.1-2410.0-05","pcs_app#2.1#ci##2.1-2410.0-05","pcs_app#2.1#co##2.1-2410.0-05","pcs_app#2.1#cc##2.1-2410.0-05","pcs_app#2.1#dq##2.1-2410.0-05","pcs_app#2.1#d2c##2.1-2410.0-05","pcs_app#2.1#df##2.1-2410.0-05"  ]}

Viewing all articles
Browse latest Browse all 582

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>