updated C++ version for JSON