Comma separated list in Liquid

Solution 1:

You might find my answer to this similar question helpful.

  1. Append each field to a string with a separator:

    {% assign metadata = "" %}
    {% if asset.metadata['field01'] %}
      {% capture metadata %}{{ metadata | append: asset.metadata['field01'] | append: "|" }}{% endcapture %}
    {% endif %}
    <!-- repeat for fields 2 & 3 -->
    
  2. Use split and join to format the string for output:

    {{ metadata | split: "|" | join: ", " }}
    

This will ensure you don't get a trailing comma in your output.