Skip to content

Conformance Examples 0.1.0 — Transforms: transform-find

find-property-value

With two arguments, returns the first struct whose property equals the value.

Template

{{ items | find: "k" "b" }}

Context

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

Output

{"k":"b","n":2}

find-property-truthy

With one argument, returns the first struct whose property is truthy.

Template

{{ items | find: "ok" }}

Context

{
    "items": [
        {
            "ok": false
        },
        {
            "ok": true,
            "id": 9
        }
    ]
}

Output

{"ok":true,"id":9}

find-no-match-is-null

When nothing matches, the result is null.

Template

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

Context

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

Output

null

find-non-list-is-null

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

Template

{{ x | find: "k" }}

Context

{
    "x": "hi"
}

Output

null

find-non-struct-contents-is-null

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

Template

{{ xs | find: "k" }}

Context

{
    "xs": [
        1
    ]
}

Output

null

Source fixture: transforms/transform-find.json