O'Neil Tomlinson
O'Neil Tomlinson

Reputation: 888

Logic App return JSON fields if its not null

How do i strip out fields of a JSON object returned in a Logic App HTTP response if the value is null?

Current response message sample:

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

But requires:

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

Thanks

Upvotes: 1

Views: 848

Answers (2)

B. Irena
B. Irena

Reputation: 169

Alternatively you could use the logic below in case you expect other fields to be empty besides the Address

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

Upvotes: 1

felixmondelo
felixmondelo

Reputation: 1474

You can do it with an Integration Account and a Liquid Map as this:

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

Using a Transform JSON to JSON shape:

enter image description here

Upvotes: 3

Related Questions