thotwielder
thotwielder

Reputation: 1707

Azure data factory get object properties from array

I have a Get Metadata activity which get all child items under a blob container. There are both files and folders but i just need files. So in a filter activity which filter for only items of type = file. This is what I got from the filter activity:

    Output
    {
        "ItemsCount": 4,
        "FilteredItemsCount": 3,
        "Value": [
            {
                "name": "BRAND MAPPING.csv",
                "type": "File"
            },
            {
                "name": "ChinaBIHRA.csv",
                "type": "File"
            },
            {
                "name": "ChinaBIHRA.csv_20201021121500",
                "type": "File"
            }
        ]
    }

So there is an array of 3 objects being returned. Each object has a name and type properties. I want just the names to be fed to a store procedure activity as a parameter. I have used this expression to try to get a comma separated list as the parameter.

    @join(activity('Filter1').output.Value.name, ',')

and got this error:

            The expression 'join(activity('Filter1').output.Value.name, ',')' cannot be evaluated because property 'name' cannot be selected. Array elements can only be selected using an integer index.

So how can I achieve this?

Upvotes: 0

Views: 7017

Answers (2)

Srivathsan V
Srivathsan V

Reputation: 21

Use the below codeblock instead

@concat(
  ''''
  ,join(
    json(
      replace(
        replace(
          replace(
            replace(
              string(activity('Filter1').output.Value)
              ,',"type":"File"'
              ,''
            )
            ,'"name":'
            ,''
          )
          ,'{'
          ,''
        )
        ,'}'
        ,''
      )
    )
    ,'''
    ,'''
  )
  ,''''
)

This would forego the use of multiple activities, and you can use the existing framework that you have.

Upvotes: 1

Steve Johnson
Steve Johnson

Reputation: 8690

You can create For Each activity after Filter activity. Within For Each activity, append file name.

Step:

1.create two variable. enter image description here

2.Setting of For Each activity enter image description here

3.Setting of Append Variable activity within For Each activity enter image description here

4.Setting of Set variable enter image description here

Upvotes: 1

Related Questions