How to filter an array of objects based on values in an inner array with jq?

前端 未结 2 1351
你的背包
你的背包 2020-11-28 18:20

Given this input:

[
  {
    \"Id\": \"cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b\",
    \"Names\": [
      \"condescending_jones\",
            


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 19:15

    Here is another solution which uses any/2

    map(select(any(.Names[]; contains("data"))|not)|.Id)[]
    

    with the sample data and the -r option it produces

    cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b
    a4b7e6f5752d8dcb906a5901f7ab82e403b9dff4eaaeebea767a04bac4aada19
    

提交回复
热议问题