Change `serialize` to `toJson` and make sure output is valid JSON.