In Azure Logic App how to iterate over a dictionary - azure-logic-apps

I am having a Azure logic app where I want to iterate over a dictionary as shown below.
"test": {"text1":"qabdstw1234",
"text2":"vhry46578"
},
Here, in my Logic app I am able to iterate over a list of dictionary but here I want to iterate over a dictionary.
Does anybody knows how to do it?

I have used parse JSON inorder to fetch test1 data from the JSON which you have provided and then used compose connector to get the same. Here is my Logic app :-
Here is the generated schema while using the sample JSON Payload which you have provided I'm using:-
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"text1": {
"type": "array",
"items": {
"type": "string"
}
},
"id": {
"type": "string"
},
"status": {
"type": "string"
}
}
}

Add a new action, search for Control and select the For each:
To process an array in your logic app, you can create a "Foreach" loop. This loop repeats one or more actions on each item in the array.
Source: Create loops that repeat workflow actions or process arrays in Azure Logic Apps

Related

How to create string variable from array in Azure LogicApps?

I have LogicApp which get HTTP Post from Azure Alerts.
I would like to create "DimensionNames" string variable, which includes all names in array.
DimensionNames value could be "name1,name2, name3, name4".
Finally I would use DimenstionNames string in "call Webhook".
How do it?
Request Body Json in "When a HTTP request is received"
{
"dimensions": {
"items": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
}
}
Using variables and Join action you can convert array to a string variable. I have reproduced from my side and below are steps I followed,
Created an alert and configured a HTTP trigger logic app to it.
Designer of logic app will be,
The payload of http request is,
{
"dimensions": {
"items": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
}
}
4. Next taken Initialize variable action as shown below,
Taken Join action to divide values from array with comma,
Next taken another initialize variable action to store value as a string,
In webhook action the value of string variable is used as body,
Outputs are shown below,
Http trigger:
Output of initialize variable,
Output if Join,
Output of initialize variable 2,
Reference link

Need to remove an item from array based on condition in groovy

I am able to fetch the subscription id and name from azure cli. Need to remove the subscriptions which has a particular string in their names. How to achieve this in groovy?
My code is as below
az account list --query '[].{name:name,id:id}
It returns the below values
[
{
"id": "66666666666666",
"name": "sub-demo-1"
},
{
"id": "22222222222222",
"name": "sub-demo-2"
},
{
"id": "000000000000000",
"name": "sub-prod-1"
},
{
"id": "888888888888888",
"name": "sub-prod-2"
}
]
I need to remove all the subscriptions which has the name demo in it. Secondly it should save only the subscription ids to another array after removing the unwanted items.
I want the below output
[
000000000000000,
888888888888888
]

Retrieve json property value in Azure Logic App

I created a simple logic app triggered by sending a json payload and I need to retrieve a value of a property in order to use it in a condition scope.
Thanks for you help
Please use Parse Json action, please click Use sample payload to generate schema, and then paste your json to generate the schema needed to parse the json:
Then select the key of the value you want to get
===============update=============================
I defined a json string as input.
According to the json string you provided, the generated schema should look like this:
{
"properties": {
"CusttId": {
"type": "string"
},
"Direction": {
"type": "string"
},
"MyId": {
"type": "string"
},
"Reason": {
"type": "string"
},
"TestDateTime": {
"type": "string"
}
},
"type": "object"
}
I did a test and it can retrieve MyId:

Multiple array definitions for single array in Azure API-management

I created a project that returns an array. Looking at the swagger.json everything looks fine, importing this swagger.json . But when I download the API definition from the developer portal I see some objects like ...Array, ...Array-1, ...Array-2. Which I don't expect:
How can I prevent this? How can I ensure that the generation behaves the same as my normal object (so no dashes, but dots). I created an example project that reproduces my issue: https://github.com/mvdiemen/SwaggerArrayGenerationExample.
Is this related to changes in Azure API management that are described over here? : https://blog.tomkerkhove.be/2018/04/13/changes-to-azure-api-management-openapi/
APIM does not support inlined schema. Try specifying schemas for response/request via $ref only, even if it's an array of object you've already defined - define a new object of type array and reference it.
So, instead of something like this:
"200": {
"description": "Success",
"schema": {
"uniqueItems": false,
"type": "array",
"items": {
"$ref": "#/definitions/SwaggerGenerationSample.Models.Response.Employee"
}
}
}
Have array itself defined in definitions and reference it:
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/EmployeeArray"
}
}
...
"definitions": {
"EmployeeArray": {
"uniqueItems": false,
"type": "array",
"items": {
"$ref": "#/definitions/SwaggerGenerationSample.Models.Response.Employee"
}
}
}

JSON schema deeper object uniqueness

I'm trying to get into JSON schema definitions and wanted to find out, how to achieve a deeper object uniqueness in the schema definition. Please look at the following example definition, in this case a simple IO of a module.
{
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"required": ["modulIOs"],
"properties": {
"modulIOs": {
"type": "array",
"uniqueItems": true,
"items": {
"allOf": [
{
"type": "object",
"required": ["ioPosition","ioType","ioFunction"],
"additionalProperties": false,
"properties": {
"ioPosition": {
"type": "integer"
},
"ioType": {
"type":"string",
"enum": ["in","out"]
},
"ioFunction": {
"type":"string"
}
}
}
]
}
}
}
}
When I validate the following with i.E. draft-06 I get a positive validation.
{"modulIOs":
[
{
"ioPosition":1,
"ioType":"in",
"ioFunction":"240 V AC in"
},
{
"ioPosition":1,
"ioType":"in",
"ioFunction":"24 V DC in"
}
]
}
I'm aware that the validation is successfull because the validator does what he's intended to - it checks the structure of a JSON-object, but is there a possibility to validate object value data in deeper objects or do i need to perform the check elsewhere?
This is not currently possible with JSON Schema (at draft-7).
There is an issue raised on the official spec repo github for this: https://github.com/json-schema-org/json-schema-spec/issues/538
If you (or anyone reading this) really wants this, please thumbsup the first issue comment.
It's currently unlikely to make it into the next draft, and even if it did, time to impleemntations picking it up may be slow.
You'll need to do this validation after your JSON Schema validation process.
You can validate data value of your object fields by using JSON schema validation.
For example, if you need to check if ioPosition is between 0 and 100 you can use:
"ioPosition": {
"type": "integer",
"minimum": 0,
"maximum": 100
}
If you need to validate ioFunction field you can use regualr expression such as:
"ioFunction": {
"type": "string",
"pattern": "^[0-9]+ V [A,D]C"
}
Take a look at json-schema-validation.

Resources