Make sure err is undefined if null, since JSON doesn't have undefined, it gets converted to null