Replies: 3 comments 3 replies
-
I think that's exactly what you need to do. The question is how. If you know the names of the potential keys you could just write out a set of nested loops. The difficulty is handling missing keys, but I would do that by iterating over If the number of arrays is unknown I think you need to write a recursive function to do it.
It does have limitations, of course, but I'm not sure those are relevant here in any way. You'd have much the same challenges in any programming language. If you think of it that way, it might perhaps help. How would you write this in your preferred, ordinary programming language? The same approach would likely work in JSLT. |
Beta Was this translation helpful? Give feedback.
-
This On the second This is nesting loops:
The parentheses are there because of weirdness in the JSLT syntax. The reason you can't refer to |
Beta Was this translation helpful? Give feedback.
-
Thanks @larsga , i start too see more clear now. At the moment i can use nested and exception on missing key to solve the problem partially ( in the case of maximum 3 known values ): Here the code:
With this the only problem is in this case: INPUT:
Since we are veryifing into each inner loop the existence of the previous element, and this elements are ordered, if one element is missing in the middle, the loop is kind interrupted earlier: OUTPUT:
while the expected output should be the cartesian product of first and third 🥲. I still think that the recursive is the best solution but absolutely not the easiest one 🤯 |
Beta Was this translation helpful? Give feedback.
-
Hello Everyone,
I am currently facing a challenge with a transformation task involving JSON data using JSLT. My goal is to perform a task similar to calculating a cartesian product with the values of the JSON object.
Here's the problem in detail:
Given the following JSON:
I aim to concatenate all the values like in a cartesian product, yielding a result like this:
The input fields are not necessarily guaranteed. The object can contain one field or multiple fields.
So far, I have attempted the following approach:
Which gives me the following result:
I was considering iterating over each sub-array, but I'm finding myself at a crossroads given JSLT's limitations. Hence, I'd highly appreciate any insights on how to approach this problem within the capabilities of JSLT.
Thank you in advance for your assistance!
Beta Was this translation helpful? Give feedback.
All reactions