TomFrost/Jexl

Transform Confusion

Opened this issue · 1 comments

So can JEXL be used as a tranform language or just an expression evaluator only?

For example, if I wanted to use JEXL against the following:

{
"name": {
"first": "Sterling",
"last": "Archer"
},
"assoc": [
{
"first": "Lana",
"last": "Kane"
},
{
"first": "Cyril",
"last": "Figgis"
},
{
"first": "Pam",
"last": "Poovey"
}
],
"age": 36
}

and simply return the array contents of "assoc" but with last names upper-cased, is that possible with JEXL? (i.e i would like to output something like this:

[
{ "first": "Lana", "last": "KANE" },
{ "first": "Cyril", "last": "FIGGIS" },
{ "first": "Pam", "last": "POOVEY" }
]

JexlPlayground

You can add the following transform (for example)
mapToUpper: (arr) => arr.map(o => ({first: o.first, last: o.last.toUpperCase()}))

And you can call it like this
assoc|mapToUpper