Appearance
Sort Objects Mutation ​
The Sort objects mutation orders a list of objects by one of their attributes, either ascending or descending, or by a priority order of patterns. It works like Sort, but orders by an attribute of each object instead of the entry itself.
Options ​
- Order: Choose between Ascending and Descending.
- Sort by attribute: The attribute the objects are ordered by. Use dot paths for nested attributes and [0] to pick an entry of a nested list. The attribute name is a value, so it can also come from a product field or the current item. Leave it empty to order by the whole object as JSON text.
- Priority order: One pattern per line. Objects whose attribute matches the first pattern come first, then objects matching the second pattern, and so on. Objects matching no pattern keep their order at the end. When a priority order is set, the Order option is not used.
- Patterns match when the attribute: How each priority pattern is matched against the attribute: includes, starts with, ends with or equals.
Attribute values that are both numbers are ordered numerically, so 2 comes before 10. All other values are ordered as text. Objects without the attribute read as empty and come first in ascending order. Sort objects needs a list of objects; a single JSON object is not a list.
Example ​
The extra field videos holds this list of videos, parsed with Parse JSON:
json
[
{ "name": "hero.mp4", "position": 10 },
{ "name": "lifestyle.mp4", "position": 2 },
{ "name": "unboxing.mp4", "position": 1 }
]Sort objects with the attribute position and the order Ascending gives unboxing, lifestyle, hero. Sort objects with the attribute name and the priority order lifestyle on the first line and hero on the second gives lifestyle, hero, unboxing.