Reputation: 1287
In logic app I have parse json data one of field is 'content' which is array of objects.
{
"content" : [ {
"type" : "substitution",
"name" : "start_time",
"value" : "4:00 p.m. PDT"
}, {
"type" : "substitution",
"name" : "app_type",
"value" : "virtual"
}, {
"type" : "substitution",
"name" : "end_time",
"value" : "4:15 p.m. PDT"
}, {
"type" : "substitution",
"name" : "organization_name",
"value" : "vivendo habitasse doctus harum platea"
}, {
"type" : "substitution",
"name" : "start_date",
"value" : "Wednesday, October 7, 2020"
} ]
}
Now I want to search in array with name and return the value if is present else empty. e.g search by name "start_time" it should return value "4:00 p.m. PDT" How Can I achieve this in logic app ? Is there any pre defined functions that lets you search
Upvotes: 0
Views: 3359
Reputation: 15734
As far as I know, there is no pre defined functions for us to implement this requirement. But we can implement it by writing code, please refer to my logic app below:
Prerequisites: You need to create an integration account and associate it with your logic app. You can refer to this document.(I think free pricing tier for integration account is enough)
1. Initialize a variable named inputName
to store the input name (here I store app_type
for test).
2. Then initialize another variable named datasource
to store the same json as yours.
3. User "Parse JSON" action to parse datasource
.
4. After that, use JS inline code to do the search.
var content = workflowContext.actions.Parse_JSON.outputs.body.content;
var inputName = "" + workflowContext.actions.Initialize_variable.inputs.variables[0].value;
var result = "";
content.forEach(item=>{
if(item.name == inputName){
result = item.value;
}
});
return result;
5. Running the logic app, it retrieve the value virtual
(which its name is app_type
).
Upvotes: 3