@@ -2525,7 +2525,7 @@ Set nested value in an object using dot-separated path notation. Creates interme
25252525{{ to_json(object=config, pretty=true) }}
25262526` ` `
25272527
2528- # ### `object_keys(object)`
2528+ # ### `object_keys(object)` / `| object_keys`
25292529
25302530Get all keys from an object as an array.
25312531
@@ -2536,38 +2536,28 @@ Get all keys from an object as an array.
25362536
25372537** Examples:**
25382538` ` ` jinja
2539- {# Get all keys #}
2539+ {# Function syntax #}
25402540{% set config = {"host": "localhost", "port": 8080, "debug": true} %}
25412541{% set keys = object_keys(object=config) %}
25422542{{ to_json(object=keys) }}
25432543{# Output: ["host","port","debug"] #}
25442544
2545- {# Iterate over keys #}
2546- {% set config = {"host": "localhost", "port": 8080, "debug": true} %}
2547- Configuration keys:
2548- {% for key in object_keys(object=config) %}
2549- - {{ key }}
2550- {% endfor %}
2551- {# Output:
2552- Configuration keys:
2553- - host
2554- - port
2555- - debug
2556- #}
2545+ {# Filter syntax #}
2546+ {% set keys = config | object_keys %}
2547+ {{ keys | join(sep=", ") }}
2548+ {# Output: host, port, debug #}
25572549
2558- {# Dynamic configuration display #}
2559- {% set config = {
2560- "SERVER_HOST": "localhost",
2561- "SERVER_PORT": 8080,
2562- "DATABASE_URL": "postgres://localhost/mydb"
2563- } %}
2564- # Environment Variables
2565- {% for key in object_keys(object=config) %}
2566- {{ key }}={{ config[key] }}
2550+ {# Iterate over keys with filter syntax #}
2551+ {% for key in config | object_keys %}
2552+ - {{ key }}: {{ config[key] }}
25672553{% endfor %}
2554+
2555+ {# Chaining - get count of keys #}
2556+ {{ config | object_keys | length }}
2557+ {# Output: 3 #}
25682558` ` `
25692559
2570- # ### `object_values(object)`
2560+ # ### `object_values(object)` / `| object_values`
25712561
25722562Get all values from an object as an array.
25732563
@@ -2578,30 +2568,27 @@ Get all values from an object as an array.
25782568
25792569** Examples:**
25802570` ` ` jinja
2581- {# Get all values #}
2571+ {# Function syntax #}
25822572{% set config = {"a": 1, "b": 2, "c": 3} %}
25832573{% set values = object_values(object=config) %}
25842574{{ to_json(object=values) }}
25852575{# Output: [1,2,3] #}
25862576
2587- {# Process all values #}
2577+ {# Filter syntax #}
25882578{% set ports = {"http": 80, "https": 443, "app": 8080} %}
2589- Open ports:
2590- {% for port in object_values(object=ports) %}
2579+ {% for port in ports | object_values %}
25912580 - {{ port }}
25922581{% endfor %}
25932582{# Output:
2594- Open ports:
25952583 - 80
25962584 - 443
25972585 - 8080
25982586#}
25992587
2600- {# Mixed type values #}
2601- {% set config = {"str": "hello", "num": 42, "bool": true} %}
2602- {% for value in object_values(object=config) %}
2603- Value: {{ value }} (type: {{ type_of(value=value) }})
2604- {% endfor %}
2588+ {# Chaining filters #}
2589+ {% set scores = {"alice": 95, "bob": 87, "charlie": 92} %}
2590+ Average: {{ scores | object_values | array_avg }}
2591+ {# Output: Average: 91.33... #}
26052592` ` `
26062593
26072594# ### `object_has_key(object, key)`
@@ -2793,7 +2780,7 @@ Rename object keys using a mapping.
27932780{% set api_data = object_rename_keys(object=response, mapping={"userId": "user_id", "createdAt": "created_at"}) %}
27942781` ` `
27952782
2796- # ### `object_flatten(object, delimiter)`
2783+ # ### `object_flatten(object, delimiter)` / `| object_flatten`
27972784
27982785Flatten a nested object to dot-notation keys.
27992786
@@ -2804,22 +2791,25 @@ Flatten a nested object to dot-notation keys.
28042791** Returns:** A flat object with delimited keys
28052792
28062793` ` ` jinja
2794+ {# Function syntax #}
28072795{% set nested = {"server": {"host": "localhost", "port": 8080}, "database": {"name": "mydb"}} %}
2808-
2809- {# Default dot delimiter #}
28102796{% set flat = object_flatten(object=nested) %}
28112797{{ flat | tojson }}
28122798{# Output: {"server.host":"localhost","server.port":8080,"database.name":"mydb"} #}
28132799
2814- {# Custom delimiter #}
2815- {% set flat_underscore = object_flatten(object= nested, delimiter="_") %}
2816- {{ flat_underscore | tojson }}
2817- {# Output: {"server_host":" localhost","server_port":8080,"database_name":"mydb"} #}
2800+ {# Filter syntax #}
2801+ {% set flat = nested | object_flatten %}
2802+ {{ flat["server.host"] }}
2803+ {# Output: localhost #}
28182804
2819- {# Useful for environment variable generation #}
2820- {% for key, value in object_flatten(object=config, delimiter="_") %}
2821- export {{ key | upper }}="{{ value }}"
2822- {% endfor %}
2805+ {# Filter syntax with delimiter #}
2806+ {% set flat_underscore = nested | object_flatten(delimiter="_") %}
2807+ {{ flat_underscore["server_host"] }}
2808+ {# Output: localhost #}
2809+
2810+ {# Chaining - get all flattened keys #}
2811+ {{ nested | object_flatten | object_keys | join(sep=", ") }}
2812+ {# Output: server.host, server.port, database.name #}
28232813` ` `
28242814
28252815# ### `object_unflatten(object, delimiter)`
0 commit comments