Add json_encoder to write method.