Appearance
Lists of Objects ​
Many product sources hold structured data: a list of videos with a URL and a name, a size chart, a set of variants with a price each. Feedr can work with this data as JSON objects and lists of objects.
A JSON object is a set of attributes:
json
{ "name": "hero.mp4", "url": "https://cdn.example.com/hero.mp4" }A list of objects is a JSON array where every entry is an object:
json
[
{ "name": "hero.mp4", "url": "https://cdn.example.com/hero.mp4" },
{ "name": "lifestyle.mp4", "url": "https://cdn.example.com/lifestyle.mp4", "duration": 12 }
]A few rules apply to every mutation that reads attributes:
- Attributes can differ per object. One object may have a duration, the next may not.
- A missing attribute reads as empty. Reading duration from the first object above gives an empty value, it does not fail.
- Attribute names are matched exactly. Name and name are two different attributes.
- Nested attributes use dot paths and list indexes. Use address.city to read inside a nested object and images[0] to pick the first entry of a nested list. A path can continue after the index, as in sources[0].url, or stop at it, in which case the entry itself is read (an object or a list as compact JSON text).
Objects and lists are different values ​
A single object and a list of objects are two different values, and each mutation expects one of them:
- Object mutations work on a single object: Extract attribute.
- List mutations work on a list of objects: Find object, Pluck attribute, Filter objects, Sort objects, Count objects and Take.
The plain list mutations such as Filter and Sort have no attribute option. Their JSON twins in the JSON category do the same work on a list of objects and let you name the attribute.
Find object is the step from a list to a single object: it returns the first matching object. There is no step from a single object back to a list: a single object can only be read with Extract attribute.
Where objects and lists of objects come from ​
- The Parse JSON mutation. Apply Parse JSON to any text field that holds JSON: a product attribute, an extra field imported from your shop, or an internal field. An array of objects gives a list of objects, and a single object gives an object.
- Internal fields. An internal field with the value type Objects (JSON) hands its object or list of objects to every mapping that uses it, so the JSON is parsed once and reused.
When a text mutation such as Add prefix runs on a list of objects, each object is first turned into its compact JSON text, so the mutation applies to one text per object. A single object is turned into one text. To get one JSON text for the whole list instead, use Stringify JSON.
Repeating list items ​
Some channels need a nested element per entry of a list, for example one <video> element with a <url> and a <title> child for every video. In a nested output field (a parent field with child fields), open a list item and turn on Repeat this item for each entry in a list, then pick the list to repeat over. Any list works: a list of objects gives one item per object, and a plain list such as tags, image links or a static list gives one item per entry. A single object or a single text renders nothing.
Inside a repeating item, every child value can use Current item in the value picker. For a list of objects, type an attribute path such as url or name to read that attribute of the current object. Two reserved attributes work for every list:
- @index gives the position of the entry in the list, starting at 0.
- @value gives the entry itself: the text of a plain list entry, or the current object as compact JSON text.
For example, to output one <image> element per image link, repeat the item over the images field and map the child from Current item with the attribute @value.
Example ​
An extra field videos holds the JSON above. To output the URL of every video whose name contains hero:
- Pick the extra field videos.
- Add Parse JSON.
- Add Filter objects with operation keep, attribute name, condition includes and value hero.
- Add Pluck attribute with attribute url.
The result is a list with one entry: https://cdn.example.com/hero.mp4.
To read one attribute from one object instead, use Find object followed by Extract attribute.
Quicklook shows objects and lists of objects as a small table per object, and shows repeated list items once per list entry.