diff --git a/source/common/json/json_internal.cc b/source/common/json/json_internal.cc index b01ac6e7863b..7065e880fb71 100644 --- a/source/common/json/json_internal.cc +++ b/source/common/json/json_internal.cc @@ -525,7 +525,9 @@ std::vector Field::asObjectArray() const { std::string Field::asJsonString() const { nlohmann::json j = asJsonDocument(); - return j.dump(); + // Call with defaults except in the case of UTF-8 errors which we replace + // invalid UTF-8 characters instead of throwing an exception. + return j.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace); } bool Field::empty() const {