Join values of a field in a JSON array

I get following array from a API query in JSON

{
    "category": [{
          "id": 28,
          "name": "Dogs"
      },
      {
          "id": 14,
          "name": "Cats"
      },
      {
          "id": 878,
          "name": "Sheep"
      }]
}

The output I need is a joined list - Dogs,Cats,Sheep
I tried figuring it out with Javascript code and found some codes using .map but apparently those functions are not available.

Can someone help please ?

Use the Query JSON column:

$join(category.name,', ')

4 Likes

The method that Darren shared is great! Just tried with JS because you have mentioned that couldn’t do this with JS and I wanted to know if that is true! :raised_hands: :smiley:
( Hope I’m correct with the code! If not please let me know because love to fix them and learn! )

Here’s what I got! :

image

image

JavaScript Code :

const categories = JSON.parse(p1);
const names = categories.category.map(category => category.name);
const csv = names.join(',');
return csv;

Thank you

3 Likes

You should start using JSONata if you get access to the column Darren mentioned. It’s much shorter than normal JS.

1 Like

Perfect…it worked as you said…

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.