Skip to content

Mimic string pair fix#2290

Merged
stephenberry merged 1 commit intomainfrom
mimic-string-pair
Jan 31, 2026
Merged

Mimic string pair fix#2290
stephenberry merged 1 commit intomainfrom
mimic-string-pair

Conversation

@stephenberry
Copy link
Owner

@stephenberry stephenberry commented Jan 31, 2026

Fix mimic = std::string not working in std::vector<std::pair<...>> (Issue #2285)

Problem

When a custom type with mimic = std::string was used as a key in std::vector<std::pair<...>>, JSON writing worked correctly but reading failed with an expected_quote error.

struct string_like {
    std::string str;
};

template<>
struct glz::meta<string_like> {
    using mimic = std::string;
    static constexpr auto value = &string_like::str;
};

std::vector<std::pair<string_like, string_like>> v;
// Writing produces: {"key1":"value1","key2":"value2"}
// Reading failed with: expected_quote

Cause

The JSON read code was missing mimics_str_t checks in two locations where pair keys are parsed, while the write code correctly handled this case.

Fix

Added mimics_str_t to the key type checks in include/glaze/json/read.hpp:

  1. Line 2776 - from<JSON, pair_t<T>> specialization
  2. Line 2382 - from<JSON, readable_array_t<T>> specialization for vector-of-pairs

@stephenberry stephenberry merged commit 94cccbc into main Jan 31, 2026
42 checks passed
@stephenberry stephenberry deleted the mimic-string-pair branch January 31, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mimic = std::string doesn't work correctly when type used in std::vector<std::pair<...>>

1 participant