Here you go, I had to solve a similar problem... Credit to @andrew-coleman for the initial example
(
$dotsToUnderscores := $each(?, function($v, $k) {
{
$replace($k, '.', '_'): $type($v) = 'object' ? $dotsToUnderscores($v) :
$type($v) = 'array' ? $map($v, function($vv) { $dotsToUnderscores($vv) } :
$v
}
}) ~> $merge;
$dotsToUnderscores($)
)