How to validate JSON field in Azure data factory?

Subedi, Manish 40 Reputation points
2023-09-01T17:05:28.79+00:00

Hi,
I am looking similar isJson function(sqlserver) in Azure data factory dataflow, which can validate if a data value is json format or not?

Is there any such way in ADF to validate if a column data is Json?

Scenario: have a column RETAILER_ITEM_DESC_JSON (created from concatenating multiple columns) which is supposed to be in json format.
Expected result:
If its not in json format, example if we receive double quotes or semicolon in the data file. Then throw it as error
User's image

Thank you!

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,574 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Agarwal, Rahul 0 Reputation points
    2023-09-04T04:13:10.2766667+00:00

    Here is an example of how you might flag an error when a derived column does not contain proper JSON (using a hypothetical regex to test for JSON):

    if(
       !regexMatch(yourColumn, 'your-json-regex-here'),
       'Error',
       yourColumn
    )
    

    Remember to replace 'your-json-regex-here' with an actual regex pattern that matches valid JSON. Note that writing a regular expression to match all valid JSON strings can be extremely complicated, but you might be able to write a simpler one that matches your specific use case.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.