Skip to content

Conformance Examples 0.1.0 — Transforms: transform-map

map-simple-key

A bare property name is resolved as a KPointer dot-notation segment and 'just works'.

Template

{{ items | map: "name" }}

Context

{
    "items": [
        {
            "name": "a"
        },
        {
            "name": "b"
        }
    ]
}

Output

["a","b"]

map-nested-rfc6901-pointer

A leading-slash argument is resolved as a strict RFC 6901 JSON Pointer for nested access.

Template

{{ items | map: "/addr/city" }}

Context

{
    "items": [
        {
            "addr": {
                "city": "NYC"
            }
        },
        {
            "addr": {
                "city": "LA"
            }
        }
    ]
}

Output

["NYC","LA"]

map-nested-dot-notation

A dotted argument is resolved as nested dot-notation for nested access.

Template

{{ items | map: "addr.city" }}

Context

{
    "items": [
        {
            "addr": {
                "city": "NYC"
            }
        },
        {
            "addr": {
                "city": "LA"
            }
        }
    ]
}

Output

["NYC","LA"]

map-missing-property-is-null-element

A struct missing the property contributes a null element to the result list.

Template

{{ items | map: "name" }}

Context

{
    "items": [
        {
            "name": "a"
        },
        {
            "x": 1
        }
    ]
}

Output

["a",null]

map-non-list-is-null

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

Template

{{ x | map: "name" }}

Context

{
    "x": "hi"
}

Output

null

map-non-struct-contents-is-null

map expects a list of structs; non-struct contents yield null for the whole result.

Template

{{ xs | map: "name" }}

Context

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

Output

null

Source fixture: transforms/transform-map.json