Skip to content

Conformance Examples 0.1.0 — Transforms: transform-where

where-property-value

With two arguments, keeps structs whose property equals the value.

Template

{{ items | where: "k" "a" }}

Context

{
    "items": [
        {
            "k": "a",
            "v": 1
        },
        {
            "k": "b",
            "v": 2
        }
    ]
}

Output

[{"k":"a","v":1}]

where-property-truthy

With one argument, keeps structs whose property is truthy.

Template

{{ items | where: "on" }}

Context

{
    "items": [
        {
            "on": true,
            "id": 1
        },
        {
            "on": false,
            "id": 2
        }
    ]
}

Output

[{"on":true,"id":1}]

where-no-match-is-empty-list

When nothing matches, the result is an empty list.

Template

{{ items | where: "k" "z" }}

Context

{
    "items": [
        {
            "k": "a"
        }
    ]
}

Output

[]

where-non-list-is-null

where operates only on lists; a string input yields null.

Template

{{ x | where: "k" }}

Context

{
    "x": "hi"
}

Output

null

where-non-struct-contents-is-null

where expects a list of structs; non-struct contents yield null.

Template

{{ xs | where: "k" }}

Context

{
    "xs": [
        1,
        2
    ]
}

Output

null

Source fixture: transforms/transform-where.json