I am working on a logical decoder and would like to convert a heap tuple to JSON (a HeapTuple obtained from ReorderBufferChange). It is the moral equivalent of tuple_to_stringinfo in test_decode.c:
It seems like the easiest and best thing to do is to rely on Postgres’s native JSON serialization. A HeapTuple is not a Datum; but reading heaptuple.c they seem to have a close relationship. Do arrays of Datum become HeapTuple? Is a HeapTuple basically Datum sans type information? What is the best way to convert a HeapTuple to a Datum?