var input = JSON.parse(value),
    output = [];

input.forEach(function (sensor) {
    sensor.metrics.forEach(function (metric) {
        output.push(
            {
                '{#SENSOR_ID}': sensor.id,
                '{#SENSOR_NAME}': sensor.name,
                '{#GATEWAY_ID}': sensor.gateway.id,
                '{#GATEWAY_NAME}': sensor.gateway.name,
                '{#METRIC}': metric.name,
                '{#UNIT}': metric.unit
            }
        );
    })
});

return JSON.stringify(output);