Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add built-in filter to flatten a nested array #42

Open
derkork opened this issue Jun 13, 2022 · 0 comments
Open

add built-in filter to flatten a nested array #42

derkork opened this issue Jun 13, 2022 · 0 comments

Comments

@derkork
Copy link
Owner

derkork commented Jun 13, 2022

When you do json-paths with foo[*].* you get nested arrays. while this is okay, sometimes you need to unwrap these into a single array. it would therefore be nice to have a function that would flatten one level of arrays in an array

{% let stuff = [[1,2,3], 4, [5,6,[7,8]] %}
{{ stuff | flatten }} {# prints [1,2,3,4,5,6,[7,8]] #}
{{ stuff | flatten | flatten }} {# prints [1,2,3,4,5,6,7,8] #}

Maybe also add a flatten_all filter which flattens until the array no longer contains any other arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant