Unify json serialization. Also log errors.