-
-
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
json stringify #1532
Comments
Could you please provide an example? Like a JSON value, the result of |
Yes. { "key": "text" , "data": "hello world!" } I want it to became:
and the same for '' to became '\'. |
I see. But the resulting string would not be valid JSON text, so adding the backslashes would not make sense for this library. What you could try (though it would not touch #include "json.hpp"
#include <iostream>
using json = nlohmann::json;
int main() {
json j = R"( { "key": "text" , "data": "hello world!" } )"_json;
std::cout << json(j.dump()).dump() << std::endl;
} result:
|
I think adding the backslashes is out of scope of the library, so I add the "won't fix" label. |
Sounds like you want this:
|
Now that I read the previous comments better, this looks to be the same basic idea that @nlohmann posted, including not quoting single quotes. |
what about the function escape_string that you provided here:
https://github.com/nlohmann/json/blob/ec7a1d834773f9fee90d8ae908a0c9933c5646fc/src/json.hpp#L4604-L4697
?
בתאריך יום ד׳, 20 במרץ 2019 ב-17:13 מאת gregmarr <
notifications@github.com>:
… Now that I read the previous comments better, this looks to be the same
basic idea that @nlohmann <https://github.com/nlohmann> posted, including
not quoting single quotes.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1532 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/Aey8wFJCdy1widFAn0nGBYsa1n52wyn7ks5vYlAjgaJpZM4b_bnk>
.
--
אלעד פוטוק
|
@eladpotok Do you need further assistance on this issue? |
I actually think providing |
Is that free function any more than this? (I know this is completely unconstrained, and doesn't guarantee strings, but just for the basic idea).
|
Yes, it's that, but avoids the mandatory copy (in the |
The library works very good for my needs. But there is an addition that could be very helpful.
I need a way to stringify the result from the json.dump() function.
For every " or ' that appears in the json, need to be escaped -- " or '.
Thanks,
The text was updated successfully, but these errors were encountered: