Skip to content

Conformance Examples 0.1.0 — Transforms: transform-compact

compact-removes-nulls

Null elements are removed from the list; surviving elements keep their order.

Template

{{ xs | compact }}

Context

{
    "xs": [
        1,
        null,
        2,
        null,
        3
    ]
}

Output

[1,2,3]

compact-no-nulls

A list with no null elements is returned unchanged.

Template

{{ xs | compact }}

Context

{
    "xs": [
        "a",
        "b"
    ]
}

Output

["a","b"]

compact-non-list-is-null

A non-list input does not match the transform's shape, so the result is null.

Template

{{ x | compact }}

Context

{
    "x": "hello"
}

Output

null

compact-null-input-is-null

A null (missing) input is not a list, so the result is null.

Template

{{ missing | compact }}

Context

{}

Output

null

compact-keeps-non-primitive-elements

Non-primitive elements (structs) are not null, so compact keeps them.

Template

{{ xs | compact }}

Context

{
    "xs": [
        {
            "a": 1
        },
        null,
        2
    ]
}

Output

[{"a":1},2]

Source fixture: transforms/transform-compact.json