Generalize codecs. Add JSON handling.