question

TonyCasey-4877 avatar image
0 Votes"
TonyCasey-4877 asked ChaitanyaNaykodiMSFT-9638 answered

Parse Json schema response

I have searched high and low for this and cannot find a solution.

I want to create a response schema for my Logic App.

The app selects data from the document db which includes metadata fields like _etag, _ts, _rid etc.

I want to remove those fields from the reponse object.

I tried Parse Json and it just ignores the schema and adds in all the fields I don't want.

Here is the input it gets..

 [
   {
     "id": "1",
     "provider": "Microsoft",
     "examCode": "AZ-900",
     "body": "Question 1 about blah blah blah",
     "_rid": "vLoPANg8VjcBAAAAAAAAAA==",
     "_self": "dbs/vLoPAA==/colls/vLoPANg8Vjc=/docs/vLoPANg8VjcBAAAAAAAAAA==/",
     "_etag": "\"79001ad3-0000-0d00-0000-60e823830000\"",
     "_attachments": "attachments/",
     "_ts": 1625826179
   }
 ]

Here is the schema..

 {
   "type": "array",
   "items": {
     "type": "object",
     "properties": {
       "body": {
         "type": "string"
       },
       "examCode": {
         "type": "string"
       },
       "id": {
         "type": "string"
       },
       "provider": {
         "type": "string"
       }
     },
     "required": [
       "id",
       "provider",
       "examCode",
       "body"
     ]
   }
 }

Here is the output..

 [
   {
     "id": "1",
     "provider": "Microsoft",
     "examCode": "AZ-900",
     "body": "Question 1 about blah blah blah",
     "_rid": "vLoPANg8VjcBAAAAAAAAAA==",
     "_self": "dbs/vLoPAA==/colls/vLoPANg8Vjc=/docs/vLoPANg8VjcBAAAAAAAAAA==/",
     "_etag": "\"79001ad3-0000-0d00-0000-60e823830000\"",
     "_attachments": "attachments/",
     "_ts": 1625826179
   }
 ]


So what's the point of Parse Json if it doesn't follow the schema?


azure-logic-apps
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @TonyCasey-4877, if possible could you please share a screenshot of the designer view of the implementation? As the input received is of type array you might have to run a loop to get the individual fields.

0 Votes 0 ·
TonyCasey-4877 avatar image
0 Votes"
TonyCasey-4877 answered shashishailaj converted comment to answer

@ChaitanyaNaykodiMSFT-9638

So, back to the original question then.

The ParseJson will NOT parse an array into the supplied schema.

If I want to get the individual fields, I will have to loop through the array, add them to a new array and output that one, which I have done.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ChaitanyaNaykodiMSFT-9638 avatar image
0 Votes"
ChaitanyaNaykodiMSFT-9638 answered

Hello @TonyCasey-4877, apologies for the delay in my response.

If the data received from Cosmos DB always has a single element in the array you can try to implement the solution as shown below without looping through the data.

In Parse JSON operation you can access the first object of the array by editing the Content in following manner triggerBody()[0]

117582-image.png

Just make sure to remove the array braces [ ] from the schema defined.

Please let me know if there are any concerns. Thank you!




image.png (30.4 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ChaitanyaNaykodiMSFT-9638 that would be a solution, if, as you say, there is one element in the array. But, there are many elements in the array.

0 Votes 0 ·

Hello @TonyCasey-4877, if there are multiple elements in the array then you will have to loop through them in order to get the respective individual fields.

0 Votes 0 ·
TonyCasey-4877 avatar image
0 Votes"
TonyCasey-4877 answered

It was receiving an array from the Cosmos db.

I have changed it now, to loop through the array and add to a variable.

A nicer solution would be for the ParseJson process to do the work for me :-)

116654-image.png



image.png (48.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.