Serialize C++ objects to json

This article shows how to serialize c++ objects to json in Visual Studio, while debugging the program, without writing any code.

Sample code

// Nested container with custom class
std::vector<std::map<std::string, Person>> people_vector = {
    {{"person1", Person("Alice", 30)}, {"person2", Person("Bob", 25)}},
    {{"person3", Person("Charlie", 35)}, {"person4", Person("David", 28)}}
};
Steps to serialize people_vector to json:
  1. Create a simple c++ program with the above code snippet.
  2. Compile the program and place a breakpoint after the people_vector definition.
  3. Start debugging the program and run it until it hits the breapoint.
  4. Go to Extensions->VSDebugPro menu and open Console.
  5. Print or export the object to json with the following command
print -j people_vector
export -j people.json people_vector

The print and export commands are using the Visual Studio C++ debugger interface to automatically evaluate and expand people_vector into a full json representation.