[enter image description here](https://i.sstatic.net/kpgRJCb8.png)
1. Initialize your / JSON Object given
2. Parse JSON - Converting JSON Object in to structured data object to easy manipulate for programming.
3. Compose action to get out put required:
```
{
"email": "donal.duc@waltdisney.com",
"first name": "Donald",
"last name": "Duck"
}
```
4. Schema for reference:
```
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"triggers": {
"When_a_HTTP_request_is_received": {
"type": "Request",
"kind": "Http"
}
},
"actions": {
"Parse_JSON": {
"runAfter": {
"Initialize_JSON_Object": [
"Succeeded"
]
},
"type": "ParseJson",
"inputs": {
"content": "@variables('JSON Object')",
"schema": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"phone number": {
"type": "string"
},
"fields": {
"type": "array",
"items": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"value": {
"type": "string"
},
"id": {
"type": "integer"
}
},
"required": [
"description",
"value",
"id"
]
}
}
}
}
}
},
"Initialize_JSON_Object": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "JSON Object",
"type": "object",
"value": {
"email": "donald.duck@waltdisney.com",
"phone number": "+123 321 111 333",
"fields": [
{
"description": "name",
"value": "Mickey",
"id": 1
},
{
"description": "first name",
"value": "Donald",
"id": 1
},
{
"description": "last name",
"value": "Duck",
"id": 3
},
{
"description": "age",
"value": "1",
"id": 4
}
]
}
}
]
}
},
"Compose": {
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Compose",
"inputs": {
"email": "@{body('Parse_JSON')?['email']}",
"@{body('Parse_JSON')?['fields'][1]['description']}": "@{body('Parse_JSON')?['fields'][1]['value']}",
"@{body('Parse_JSON')?['fields'][2]['description']}": "@{body('Parse_JSON')?['fields'][2]['value']}"
}
}
},
"outputs": {},
"parameters": {
"$connections": {
"type": "Object",
"defaultValue": {}
}
}
},
"parameters": {
"$connections": {
"type": "Object",
"value": {}
}
}
}
```
This is something that will work.
[![enter image description here][1]][1]
In Initialize variable step, I have initialized an array variable called finalresult with an initial value of []. This will store the final array of JSON results.
[![enter image description here][2]][2]
In my For each step, I'm first parsing each output to fetch the individual attributes. I'm then composing a result using the attributes and renaming some of the properties. Below is what I'm using as my input.
{
"BitcoinAmount": @{body('Parse_JSON')?['volume']},
"UsdtAmount": @{body('Parse_JSON')?['funds']},
"created_at": @{body('Parse_JSON')?['created_at']},
"market": @{body('Parse_JSON')?['market']},
"price": @{body('Parse_JSON')?['price']},
"side": @{body('Parse_JSON')?['side']}
}
Finally I'm appending the result into my finalresult array variable.
[![enter image description here][3]][3]
After the for each, I'm responding to my API call with my finalresult response.
My full logic app code is below.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "finalresult",
"value": "@outputs('Compose')"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "AppendToArrayVariable"
},
"Compose": {
"inputs": {
"BitcoinAmount": "@body('Parse_JSON')?['volume']",
"UsdtAmount": "@body('Parse_JSON')?['funds']",
"created_at": "@body('Parse_JSON')?['created_at']",
"market": "@body('Parse_JSON')?['market']",
"price": "@body('Parse_JSON')?['price']",
"side": "@body('Parse_JSON')?['side']"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Compose"
},
"Parse_JSON": {
"inputs": {
"content": "@items('For_each')",
"schema": {
"properties": {
"created_at": {
"type": "string"
},
"funds": {
"type": "string"
},
"id": {
"type": "integer"
},
"market": {
"type": "string"
},
"price": {
"type": "string"
},
"side": {},
"volume": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
}
},
"foreach": "@body('HTTP')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"HTTP": {
"inputs": {
"method": "GET",
"uri": "https://api.wazirx.com/api/v2/trades?market=btcusdt"
},
"runAfter": {},
"type": "Http"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "finalresult",
"type": "array",
"value": []
}
]
},
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Response": {
"inputs": {
"body": "@variables('finalresult')",
"statusCode": 200
},
"kind": "http",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Response"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
[1]: https://i.sstatic.net/MxfNA.jpg
[2]: https://i.sstatic.net/ww0Ts.jpg
[3]: https://i.sstatic.net/KpYdR.jpg