How can I check if a JSON field exists using an ADF expression?

Viewed 1284

I want to do some activity in an ADF pipeline, but only if a field in a JSON output is present. What kind of ADF expression can I use to check that?

1 Answers

I set up two json files for testing, one with a firstName attribute and one without:

test json files

I then created a Lookup activity to get the contents of the JSON file and a Set Variable activity for testing the expression. I often use these to test expressions and it's a good way to test and view expression results iteratively:

Synapse pipeline

I then created a Boolean variable (which is one of the datatypes supported by Azure Data Factory and Synapse pipelines) and the expression I am using to check the existence of the attribute is this:

@bool(contains(activity('Lookup1').output.firstRow, 'firstName'))

You can then use that boolean variable in an If activity, to execute subsequent activities conditionally based on the value of the variable.

Related