Since you're interested in readability, you may also like std::format:
std::string format_parse_error(std::string base, JSONToken token) {
std::ostringstream s;
s << "Unexpected token '" << token.value << "', type '"
<< JSONTokenType_to_string(token.type) << "', index ";
s << std::endl << base;
return format_error(s.str(), *token.full_source, token.location);
}
becomes
std::string format_parse_error(std::string_view base, JSONToken token) {
return format_error(
std::format(
"Unexpected token '{}', type '{}', index '{}'\n{}"
, token.value
, JSONTokenType_to_string(token.type)
, index
, base)
, *token.full_source
, token.location
);
}