diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index c682e72dc..864038078 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -901,7 +901,9 @@ class binary_writer return ubjson_prefix(v, use_bjdata) == first_prefix; }); - if (same_prefix && !(use_bjdata && std::string("[{SHTFNZ").find(static_cast(first_prefix)) != std::string::npos)) + std::vector bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type + + if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) { prefix_required = false; oa->write_character(to_char_type('$')); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 974653623..2ebceca74 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14800,7 +14800,9 @@ class binary_writer return ubjson_prefix(v, use_bjdata) == first_prefix; }); - if (same_prefix && !(use_bjdata && std::string("[{SHTFNZ").find(static_cast(first_prefix)) != std::string::npos)) + std::vector bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type + + if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) { prefix_required = false; oa->write_character(to_char_type('$'));