Calling Method Nlohmann: :Json: :Dump from Visual Studio Intermediate Window

Calling Method Nlohmann: :Json: :Dump from Visual Studio Intermediate Window

I'm trying to dump object from type nlohmann::json into readable string value from visual studio debugger. So in order to invoke the dump method from the nlohmann::json instance, i use visual studio intermediate window.

However, it seems like this method doesn't run well and return too few arguments in function call error although i called it exactly as I should. Also, if I try to set its output to a new std::string type, the debugger cannot identify it.

myJsonObj
{m_type=object (1 '\x1') m_value={object=0x000001303ea66590 { size=2 } array=0x000001303ea66590 { size=1152921422937066337 } ...} }
    m_type: object (1 '\x1')
    m_value: {object=0x000001303ea66590 { size=2 } array=0x000001303ea66590 { size=1152921422937066337 } string=0x000001303ea66590 "0A_>0\x1" ...}

myJsonObj.dump()
too few arguments in function call

std::string x = myJsonObj.dump()
identifier "x" is undefined

Any idea how to do it properly ?

1 Answer

In the intermediate window, we cannot use the default parameter for the C++ function. You can invoke the dump method like this:

myJsonObj.dump(4, ' ', true, nlohmann::detail::error_handler_t::strict)

However, in the intermediate window, we cannot see a pretty formatted print. You can use the Visual Studio Watch Window to the display returned string. Please see the link here to know about how to use the Watch window: How to make Visual Studio's Immediate window give me plain string output?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.