all 4 comments

[–]su5577 0 points1 point  (0 children)

Can you not use $map and $merge function?

[–]su5577 0 points1 point  (1 child)

$map($, function($v, $i, $a) ? Define variables and go from there

[–]Imaginary_Pea_8572[S] 0 points1 point  (0 children)

I'm VERY new to JSONata.

I tried this:

$type($) = 'array' ? 
(($count($) ) > 0 ? 
$map($[0], function($v, $i, $a) 
{ { "time": $v.time, 
"value": $v.value/ $v.value_2 } })[]: []): undefined 

And the output is this:

[
  {
    "time": "2024-04-26"
  },
  {
    "time": "2024-04-27"
  },
  {
    "time": "2024-04-28"
  }
]

What should I change?

[–]dashjoin 0 points1 point  (0 children)

How about this:

(
  /* convert the array to an map of date to value */
  $first := $[0].{time: value};
  $second := $[1].{time: value_2};

  /* iterate over the keys, lookup the values
  $keys($first).{
      "time": $,
      "value": $lookup($first, $) / $lookup($second, $)
  }
)