Skip to content
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

create json object from string variable #681

Closed
sivapooja opened this issue Aug 8, 2017 · 4 comments
Closed

create json object from string variable #681

sivapooja opened this issue Aug 8, 2017 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@sivapooja
Copy link

sivapooja commented Aug 8, 2017

How to create json object from string variable? i tried to create json object from string variable but doesn't work

json j = jsonStr_json

jsonStr is string variable which holds json string.

@theodelrieu
Copy link
Contributor

theodelrieu commented Aug 8, 2017

User-defined literals only work with string literals:

json j = "[0, true]"_json;

Edit: What you need is json::parse(jsonStr)

@nlohmann
Copy link
Owner

nlohmann commented Aug 8, 2017

_json only works with string literals. To create a JSON value from a string, you need to call the parse function:

json j = json::parse(jsonStr);

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Aug 8, 2017
@nlohmann
Copy link
Owner

nlohmann commented Aug 8, 2017

@sivapooja Does this solve your issue?

@sivapooja
Copy link
Author

Yes, Thank you

@nlohmann nlohmann closed this as completed Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants