04-21-2021 05:55 AM
Looking for a function to help add sequence numbers to a json array. End goal is to apply a sequence to matching values, starting with 01, subsequent values get a sequence of 02…03… 04 etc. I could do this in a mapper, or in apache velocity as part of a soap execute if possible to loop through, and apply therein.
What I have now:
[
{
“Records”: [
{
“Award”: [
“Award_A”,
“Award_C”,
“Award_A”,
“Award_B”,
“Award_C”
]
}
]
}
]
Desired output:
[
{
“Records”: [
{
“Award”: [
“Award_A”,
“Award_C”,
“Award_A”,
“Award_B”,
“Award_C”
],
“Sequence”: [
“01”,
“01”,
“02”,
“01”,
“02”
]
}
]
}
]
Solved! Go to Solution.
04-21-2021 08:49 AM
@acesario , you can also just add [0]
after @viktor_n’s expression.
$Records.map(record => record.Award.map((x, index) => record.Award.slice(0, index + 1).filter(y => y == x).length))[0]
And if you really need the “0” you can try and add .map(val => "0" + val)
So full expression is: $Records.map(record => record.Award.map((x, index) => record.Award.slice(0, index + 1).filter(y => y == x).length).map(val => "0" + val))[0]
04-21-2021 11:40 AM
My recommendation is to learn as much as you can of them, but I think most of the times are used Arrays, Strings, Objects, Dates.
04-21-2021 11:45 AM
The Expression Language is loosely based off of JavaScript expressions, so you could use JavaScript resources to try and learn some of them better. The official documentation for the language is here and we try to give some examples, although maybe they could be flushed out more. There is also a section of this community dedicated to learning it, but there isn’t a whole lot of content yet.
04-21-2021 11:48 AM
Here’s another great resource related to learning the Expression Language, where @koryknick goes over his starter pack in a video tutorial.
04-22-2021 04:57 AM
@acesario , I am not sure I understood what you mean by that ? Maybe you want something like this ?
04-22-2021 05:36 AM
No, more like :
“Records”: [
{
“Award”: [“Award_A”,“Award_B”,“Award_C”,“Award_A,“Award_B”,“Award_C”],
“Sequence”: [“01”,“01”,“01”,“02”,“02”,“02”]
“Award”: [“Award_A”,“Award_C”,“Award_A”,“Award_B”,“Award_C”],
“Sequence”: [“01”,“01”,“02”,“01”,“02”]
“Award”: [“Award_Z”,“Award_C”,“Award_A”],
“Sequence”: [“01”,“01”,“02”]
“Award”: [“Award_B”,“Award_C”,“Award_B”],
“Sequence”: [“01”,“01”,“02”]
“Award”: [“Award_A”,“Award_B”,],
“Sequence”: [“01”,“01”]
…