您在需要转换的 JSON 模板中使用 Liquid 过滤器。
您可以使用以下任何过滤器:
- 尺寸
- 切片
- 小机箱
- 网址编码
- 网址解码
- 大写
- 逃跑
- 截断
- 拆分
- StripHtml
- 脱衣舞
- Lstrip
- RsTrip
- 货币
- StripNewlines
- 加入
- 排序
- 地图
- 替换
- 先替换
- 移除
- 先删除
- 追加
- 前置
- 换行符
- 日期
- 首先
- 最后
- 加号
- 减号
- 时代
- 圆形
- 除以
- 取模
- 默认
- 独特的
- 绝对值
- 至少
- 最多
- 紧凑
在这里你可以查看它的implementation。
要转换为 JSON OUTPUT 的 JSON 模板(注意:请求输入在 {{ }} 内):
{%- 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 -%}
]
}
创建一个邮递员来测试一个带有与模板中的内容对象匹配的 JSON 正文的 POST 请求:
{
"content": {
"devices": "1,2,3,4,5",
"firstName": "Dean",
"lastName": "Ledet",
"phone": "11111111"
},
"integrationAccount": {
"map": {
"name": "SimpleJsonToJsonTemplate"
}
}
}
将输入的 Json 映射替换为您的 Liquid 映射名称。