简体   繁体   中英

JQ JSON parser, concatenate a certain child of an array

I have the following JSON input. The array is called cars. So if I do .cars I get what you see below.

Now I have to concatenate all .name elements for each item of the array. I want the output to be

Audi
VW
Audi,Honda,Chevy

Can you please help me construct the filter to output this concatenation of .name? Sometimes .name can be empty, not null, nothing just empty. So I do need a // "null" added to the filter as well. Thank you in advance.

[
  {
    "self": "link",
    "id": "18900",
    "name": "Audi",
    "releaseDate": "2015-12-11"
  }
]
[
  {
    "self": "link",
    "id": "18900",
    "name": "VW",
    "releaseDate": "2015-12-11"
  }
]
[
  {
    "self": "link",
    "id": "19400",
    "name": "Audi",
    "releaseDate": "2015-11-20"
  },
  {
    "self": "link",
    "id": "18900",
    "name": "Honda",
    "releaseDate": "2015-12-11"
  },
  {
    "self": "link",
    "id": "19201",
    "name": "Chevy",
    "releaseDate": "2016-01-08"
  }
]

这会解决您的问题吗?

.cars | map(.name? // empty) | join(",")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM