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

Parsing different json format #1241

Closed
betomoretti opened this issue Sep 16, 2018 · 4 comments
Closed

Parsing different json format #1241

betomoretti opened this issue Sep 16, 2018 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@betomoretti
Copy link

Hi there!

I would like to ask if it's possible to parse with the following structure:

{"key1":"value1","key2":"value2"}
{"key1":"value1","key2":"value2"}

This is my use case:

std::string ret(buffer);
auto j = json::parse(ret);

Thanks ! :)

@nlohmann
Copy link
Owner

You mean newline-separated JSON text?

@betomoretti
Copy link
Author

Yes! :D

@nlohmann
Copy link
Owner

If you read from a stream, then you can call the parser multiple times like this:

int main()
{
    std::stringstream ss;
    ss << "{} true false";
    
    json j;
    while (ss >> j)
    {
        std::cout << j << std::endl;
    }
}

You then only need to take care about an exception that can occur after reading the last value.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Sep 16, 2018
@betomoretti
Copy link
Author

It worked! Thanks!! I will close this issue!

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

2 participants