Forum Discussion
As I can see from the first screenshot, seems to fails on JSON Parser Snap. So, it looks like that the message being sent from the system is not valid JSON.
Hello SpiroTaleski,
Indeed, the JSON doesn't make it to the mapper, so the issue seems to be with that input...
I have taken the value that webhook.site returned for that field and validated it, it is valid JSON apparently...
I tried to check the "Non-standard JSON" option in the JSON parser snap, but there's no change, I'm still getting the error.
Any idea?
Thanks!
JF
- ionutbarna5 years agoNew Contributor II
Yes but .map() function transforms every element from the Array, I only need to change the fields where there are numbers. Is there a way that I can use conditional logic inside of the .map() function?( if typeof value == ‘number’ then value * 10 else value
Absolutely - the expression in the map function can use ternary logic just like you have in your example updating the object elements.
Assuming an input array:
{ "myArray": [ "abc", 13, "def", 15 ] }
This works as I believe you are requesting:
$myArray.map(x => x instanceof Number ? x * 10 : x){ "updatedArray": [ "abc", 130, "def", 150 ] }
- ionutbarna5 years agoNew Contributor II
You are right, in this case it works but in my case I have an array of objects which I finally managed to work with this:
jsonPath($, "$nested[*]").map(x => x.mapValues((value, key) => !isNaN(value) ? value * 10 : value))
Input:
"nested": [{"m": "hey", "o": 10, "p": "hello", "q": 100}]
Output:
"nested": [{"m": "hey", "o": 100, "p": "hello", "q": 1000}]
Thank you @koryknick for your guidance!
Related Content
- 4 months ago
- 4 months ago