Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 905
MetallicPriest Avatar asked Oct 17 '25 22:10

MetallicPriest


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.

like image 102
wBob Avatar answered Oct 22 '25 03:10

wBob