如果Logic App不为null,则返回JSON字段

时间:2018-10-07 20:34:25

标签: json http null response azure-logic-apps

如果值是null,如何去除Logic App HTTP响应中返回的JSON对象的字段?

当前响应消息示例:

{
  "Name": "John",
  "Age": 20,
  "Address": null
}

但要求:

{
  "Name": "John",
  "Age": 20,
}

谢谢

2 个答案:

答案 0 :(得分:3)

您可以使用集成帐户和液体地图来做到这一点:

{   
    {% if content.Address == empty %}
        "Name": "{{ content.Name }}",
        "Age": "{{ content.Age }}"
    {% else %}
        "Name": "{{ content.Name }}",
        "Age": "{{ content.Age }}",
        "Address": "{{ content.Address }}"
    {% endif %}
}

使用将JSON转换为JSON 形状:

enter image description here

答案 1 :(得分:1)

或者,如果您希望除“地址”之外的其他字段为空,则可以使用以下逻辑

{   
    {% if content.Name != nil %}
        "Name": "{{ content.Name }}",
    {% endif %}
    {% if content.Age != nil %}
        "Age": "{{ content.Age }}",
    {% endif %}
    {% if content.Address != nil% }
        "Address": "{{ content.Address }}"
    {% endif %}  
}