Correctly encode JSON composite elements with extensions