#Part 4 Script to Parse The Response Body Historical Data
[Music] okay so in this video we are going to write a script in order to parse our response body previously we saw how we can create a rest request not to get the response for you know to get historical data let's say and you can see here on the right side we have the response body data file that's where we have actually our response if we send a request now we're gonna get the response in that response body so what are we going to do we are going to write a script which is basically going to use the answer that we will have in the response body we're going to parse it and then we're gonna retrieve only the information that we want because the response has more data than what what is needed for us for example it has latitude longitude and I know country code city code or all these kind of information that we don't need actually to import into our table so so let's write our script so click on plus here and the pork script and give it a title so I'm going I'm going put for example powers response body so create two input variables the first one is going to be status and school code [Music] which will have the status code data bail the second one is the response body image will have the response body India bill okay so now we can use in fact the input variable status underscore code into our script so the first thing when we start our script is to check if we have a successful response to do that we are going to have a condition here input to our status underscore code if the value of this of the students coding for this 200 that means we have a successful response okay so in that case every line that we are going to write inside this condition will be executed so so what is the first thing that we do in our if condition so we are creating a local response body variable okay here which will have the past response okay the past response will be get it by using json dot parse okay and we will into parenthesis we will have the input dot response underscore body so we are taking the response from the input variable that we have into the brackets and we are parsing it and your JSON parsing okay and once we are parsing it we will have the entire results in the variable that we have created which is response body okay so once we have done this part we have to find a way how we can store all the values because we're gonna have a big length of response so what we go we are going to do is to create a narrate a summary eric the summary area will contain multiple objects each object basically represent the summary for a specific day so we're gonna have for example summary right here and then each object it is basically day one we have this number day two day three day four day five day six and so on for the entire historical data for a specific country so that's why we need to create a summary all right and then how we are going to get the value so we are going to get the value if we are going to create a loop we are going to create a loop into the entire response body we're going to loop in the entire response body and then get the values that we want for each date okay so the syntax for looping is for parentheses for I equal to 0 and I smaller than the response body length okay and for each iteration what we do we are creating our object okay you remember the summary array will have multiple object so we are creating here our first object and each object will have the country country encases the caucasus dead cases and data and they vary access the country value if you remember if you in the response body that we receive in the json string we have it in the capital country properly okay so this is how we can access the value of country with the same in the same way we're gonna get the value for all other information that we want from some cases oracle cases and it so this is for each iteration we are creating an object and we are storing all the values that evolved into our object but we have to store all the objects that we are trading into an array that's why now we are creating as we are saying to the summary array for each iteration every object which is actually created it should go inside our Eric so summary and then equal to a summary object so summary 0 you will have the summary object which is for 0 and then we're gonna have for the entire length okay so we have so we have not we will have at this point an entire array with multiple object each object will contain the summary for each day okay so now we have to find a way not output all of this so we are creating an output variable the same way we have created an input variable like status underscore underscore code and we create here output variable which is country summary equal to some rate okay so the country summary it's an array so so let's create our output variable country summary so this is an array object so make sure that you select every object here and then you create a summary object to the child item and then you create a all other child items which is country confirm cases recover cases and death and also date okay this is our output variable for our action step but for the entire action output we are going to also create exactly the same thing we can actually create a template in our action step and use it here but it's not a very big array here we don't have 25 child items so so it's I prefer to recreate so you have to just repeat the the entire thing that we have done in the previous step for the output variable so country summary array object summary object create here and then all the child items which is country then we prayed our confirm cases [Music] okay so you can do this there on the right side you have the data appeal this country summary because this is the one that we have created in this script action step that we are going to actually use in here so once we have done with this the creation here with all the child items we can just drag and drop the data pool that we have here in the script pass response body and put it directly to the action output that's how we can take the values from the script and then the action output can be used somewhere else okay so once you have done with that country we need one more one more child item which is the date item a click on exit mode just drag and drop country summary that's it save the save all changes and we are going to now test our entire action so we should have India as value so we have it click on test run test click on action so you can see here we have the result this is what you should get thanks for watching
https://www.youtube.com/watch?v=y2RfJqAwUTI