dropbox / json11

A tiny JSON library for C++11.
MIT License
2.55k stars 615 forks source link

Parse half ready json #55

Closed Dushistov closed 8 years ago

Dushistov commented 8 years ago

This patch (pull request) add ability to parse half ready json. For example if you recieve json stream from network, you can get something like this

{"k1" : "v1"}
{"k2": 

you get one full json entry, and half of next one.

At now json11 can parse {"k1" : "v1"} and give up on {"k2": - great. But json11 not return updated position in input, so it is not possible to remove {"k1" : "v1"} from internal buffer and wait for new data. This pull request solve this inconvenience.

j4cbo commented 8 years ago

Cool, thanks! A few requests:

        size_t orig_size = json_str.size();
        json_str += R"({"k2":"v2", "k3":[)";
        res = Json::parse_multi(json_str, parser_stop_pos, err);
        assert(parser_stop_pos == orig_size);
        assert(res.size() >= 1);
Dushistov commented 8 years ago

I updated branch parse_not_full_json, so pull request was changed.

Changes:

  1. rebase on top of the current master
  2. add test case based on @j4cbo 's suggestion R"({"k2":"v2", "k3":[)"
  3. use parser failed flag, instead of back().is_null - looks more readable
Dushistov commented 8 years ago

I subscribed "Dropbox Contributor License Agreement".