These 4 lines could be refactor to something like this:

```python
if "json" == encod:
    return json.dumps(serialize(data))

return serialize(data)
```