Here's the link to a tutorial I was reading over: Transform JSON and XML using Liquid templates as maps in Azure Logic Apps. It doesn't really say anything about using filters that I could code even though Microsoft uses the DotLiquid implementation of Liquid which allows the making of custom filters. I'm not sure how or where I would be able to input any custom-made filters in; has anyone tried anything like this?
1 Answers
0
votes
You use Liquid filters inside your JSON template that need to be transformated. You can use any of these filters:
- Size
- Slice
- Downcase
- UrlEncode
- UrlDecode
- Capitalize
- Escape
- Truncate
- Split
- StripHtml
- Strip
- Lstrip
- RsTrip
- Currency
- StripNewlines
- Join
- Sort
- Map
- Replace
- ReplaceFirst
- Remove
- RemoveFirst
- Append
- Prepend
- NewlineToBr
- Date
- First
- Last
- Plus
- Minus
- Times
- Round
- DivideBy
- Modulo
- Default
- Uniq
- Abs
- AtLeast
- AtMost
- Compact
Here you can check its implementation.
JSON template to be transformated as JSON OUTPUT (note: request inputs are inside {{ }}):
{%- assign deviceList = content.devices | Split: ', ' -%}
{
"fullName": "{{content.firstName | Append: ' ' | Append: content.lastName}}",
"firstNameUpperCase": "{{content.firstName | Upcase}}",
"phoneAreaCode": "{{content.phone | Slice: 1, 3}}",
"devices" : [
{%- for device in deviceList -%}
{%- if forloop.Last == true -%}
"{{device}}"
{%- else -%}
"{{device}}",
{%- endif -%}
{%- endfor -%}
]
}
Create a postman to test a POST request with a JSON body matching the content object in your template:
{
"content": {
"devices": "1,2,3,4,5",
"firstName": "Dean",
"lastName": "Ledet",
"phone": "11111111"
},
"integrationAccount": {
"map": {
"name": "SimpleJsonToJsonTemplate"
}
}
}
Replace input Json map for your Liquid map name.