-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
basic_json::iterator::value() output includes quotes while basic_json::iterator::key() doesn't #158
Comments
Thanks for reporting! I'll check! |
This is not a bug.
So if you want an escaped version of the key, you need to create a JSON value out of it first. Example: #include <json.hpp>
using nlohmann::json;
int main()
{
json s = "\"quoted\"";
json j = {{s, s}};
std::cout << "output of j (json): " << j << "\n";
std::cout << "output of the first key (std::string): " << j.begin().key() << "\n";
std::cout << "output of the first key (json): " << json(j.begin().key()) << "\n";
std::cout << "output of the first value (json): " << j.begin().value() << "\n";
std::cout << "output of the first value (std::string): " << j.begin()->get<std::string>() << "\n";
} Output:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've noticed that when iterating through a json object, calling
value()
wraps the string with quotes whilekey()
doesn't. This should be changed so that either they both be wrapped with quotes or not wrapped at all.The text was updated successfully, but these errors were encountered: