Awee

key

Key extracts a value from a map or slice by key path or index.

Key extracts a value from a map or slice by key path or index. Use dot notation to traverse nested maps.

Input

map array

Parameters

#TypeRequired
0stringyes

Returns

any

Examples

Read a top-level field

Input

user = {"name": "Alice", "email": "[email protected]"}

Template

{{ user | key:'name' }}

Output

Alice

Read a nested field with dot notation

Input

config = {"database": {"host": "db.local", "port": 5432}}

Template

{{ config | key:'database.host' }}

Output

db.local

Index into a list

Input

items = ["espresso", "latte", "macchiato"]

Template

{{ items | key:0 }}

Output

espresso

How is this guide?

On this page