Closed
Description
Description
I would like to store objects in a std::map<std::string, std::any>
. But converting nlohmann::json
to std::any
throws error type must be string, but is
I can only reproduce this issue on Windows. macOS seems working fine.
Reproduction steps
Minimal test case:
#include <any>
#include <nlohmann/json.hpp>
int main() {
nlohmann::json j;
std::any &&a = j;
return 0;
}
Expected vs. actual results
Expected: Runs without error
Actual: Exception: Exception 0xe06d7363 encountered at address 0x7ffa855c466c
Minimal code example
No response
Error messages
<unknown> 0x00007ffa855c466c
<unknown> 0x00007ffa6dcfb660
nlohmann::detail::from_json<nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > >,std::any,0>(const nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > > &,std::any &) from_json.hpp:118
nlohmann::detail::from_json_fn::operator()<nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > >,std::any &>(const nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > > &,std::any &) from_json.hpp:480
nlohmann::adl_serializer<std::any,void>::from_json<nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > > const &,std::any>(const nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > > &,std::any &) adl_serializer.hpp:25
nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > >::get_impl<std::any,0>(priority_tag<0>) json.hpp:1613
nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > >::get<std::any,std::any>() json.hpp:1756
nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer,std::vector<unsigned char,std::allocator<unsigned char> > >::operator<std::any,0> std::any() json.hpp:1900
main() main.cpp:7
invoke_main() 0x00007ff7cb0d12c9
__scrt_common_main_seh() 0x00007ff7cb0d116e
__scrt_common_main() 0x00007ff7cb0d102e
mainCRTStartup(void *) 0x00007ff7cb0d135e
<unknown> 0x00007ffa872d54e0
<unknown> 0x00007ffa87e8485b
### Compiler and operating system
MSVC 19.31.31104 on Windows 11 21H2
### Library version
current develop 15fa6a342af7b51cb51a22599026e01f1d81957b
### Validation
- [X] The bug also occurs if the latest version from the [`develop`](https://github.com/nlohmann/json/tree/develop) branch is used.
- [X] I can successfully [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests).