You can use ST_ClosestPoint()
to find the closest one to each point. If you use that in combination with make line you should be able to achieve what you need. Here is a link to the documentation for ST_ClosestPoint().
You could do it like this -
select st_asgeojson(st_makeline(g)) from
(select geometry as g from testing group by geometry order by st_closestpoint(geometry, geometry)) as f