简体   繁体   中英

Azure Logic Apps - Verify content in JSON file

I have a logic app that runs as follows:

  • Step 1 = Recurrence (the schedule for the logic app to run)
  • Step 2 = HTTP (Performing a POST call on a custom API that returns a JSON file)
  • Step 3 = Create Blob (which uploads said document from Step 2 and uploads it to blob storage)

What I would like to do now is add an extra step between Step 2 and Step 3 . After making the HTTP POST call, I would like to verify the content inside the JSON file that gets returned. If there is an error present in the JSON file, I want the Logic App to stop there.

Is there a particular step that I can use in Azure's Logic App to verify the data and have that step decide if it should continue on or not.

For this requirement, you can refer to my logic app below:

1. I initialize a variable named " resultFromHTTP " to simulate the json from your HTTP request(step 2). And I delete some character, so the " resultFromHTTP " is not a valid json format.

在此处输入图片说明

2. Then I initialize another variable and use the expression json(variables('resultFromHTTP')) in its value.

在此处输入图片说明

3. Run the logic app, it will fail and show error message like below screenshot. If the json is in valid format, it will run success.

在此处输入图片说明

=============================== Update ==============================

For your latest question, if the result json from HTTP request is not in valid json format and not a very long string, you can do it like this:

在此处输入图片说明

The contains(... expression is contains(variables('resultFromHTTP'), 'Data Not Found') . Then you can do what you want under "if true" or "if false".

If the result json from HTTP request is in valid json format, you can use " Parse JSON " action to parse it and get the specified field and then judge if it equals to "Data Not Found".

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM