-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
to_string? #1181
Comments
Does this do what you want? |
The library does not provide an automatic stringification for all value types. As @gregmarr points out, the (unescaped) string value can be queried with |
@gregmarr You're right, I completely forgot that I had used that in my switch-case statement, haha. Probably a good decision to make us do this explicitly, I've already been bitten by some of the implicitness allowed in this library and it seems like you're taking steps to move away from that, no sense introducing more :P |
@haydenflinner Do you need further assistance or can we close this issue? |
Thank you! |
Given a json object of any primitive type, I'd like to be able to call something like
std::to_string
on it, allowing me to turn it into a string without the quotes/escaping thatdump
would put on a string.So far the closest I've gotten to the behavior I want is a big switch statement on the type of the json object, where I call
std::to_string(json_val.get<thetype>())
in each case except string and raise an exception on non-primitive types.So if I have the object
{ 'lokey' : 'hival' }
, I want to be able to save the string"hival"
(where the quotes ust denote the string, in memory would just behival
) and not"\"hival\""
. I would like the same function to implicitly format bools and ints to strings, as well. I understand that this is asking for opinionated behavior, but I think it would be helpful for brevity if you were, for example, converting from one JSON schema to another, where the same thing has a different type in the two schema. At the least, letting me get just the string of a string value instead of the escaped version would be enough for me.I'm very sorry if there's already something like this in the library, I looked through the documentation multiple times over the last few days before arriving at my switch statement.
Thanks for the awesome library!
The text was updated successfully, but these errors were encountered: