Add JSON serializer

This is WIP and targets #355.