{"action":"opened","issue":{"url":"https://api.github.com/repos/nlohmann/json/issues/971","repository_url":"https://api.github.com/repos/nlohmann/json","labels_url":"https://api.github.com/repos/nlohmann/json/issues/971/labels{/name}","comments_url":"https://api.github.com/repos/nlohmann/json/issues/971/comments","events_url":"https://api.github.com/repos/nlohmann/json/issues/971/events","html_url":"https://github.com/nlohmann/json/issues/971","id":296874755,"number":971,"title":"Add a SAX parser","user":{"login":"nlohmann","id":159488,"avatar_url":"https://avatars2.githubusercontent.com/u/159488?v=4","gravatar_id":"","url":"https://api.github.com/users/nlohmann","html_url":"https://github.com/nlohmann","followers_url":"https://api.github.com/users/nlohmann/followers","following_url":"https://api.github.com/users/nlohmann/following{/other_user}","gists_url":"https://api.github.com/users/nlohmann/gists{/gist_id}","starred_url":"https://api.github.com/users/nlohmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nlohmann/subscriptions","organizations_url":"https://api.github.com/users/nlohmann/orgs","repos_url":"https://api.github.com/users/nlohmann/repos","events_url":"https://api.github.com/users/nlohmann/events{/privacy}","received_events_url":"https://api.github.com/users/nlohmann/received_events","type":"User","site_admin":false},"labels":[{"id":304694104,"url":"https://api.github.com/repos/nlohmann/json/labels/state:%20please%20discuss","name":"state: please discuss","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-13T20:29:29Z","updated_at":"2018-02-13T20:29:29Z","closed_at":null,"author_association":"OWNER","body":"The library currently only supports DOM-like parsing. This does not scale when the input files are enormous (#927). I would like to discuss how a SAX-like parser could look like.\r\n\r\nMy proposal (heavily motivated by [RapidJSON](http://rapidjson.org/md_doc_sax.html)) is as follows:\r\n\r\n```cpp\r\nstruct SAX\r\n{\r\n    // a null value was read\r\n    bool null();\r\n\r\n    // a boolean value was read\r\n    bool boolean(bool);\r\n\r\n    // an integer number was read\r\n    bool number_integer(number_integer_t);\r\n\r\n    // an unsigned integer number was read\r\n    bool number_unsigned(number_unsigned_t);\r\n\r\n    // a floating-point number was read\r\n    // the string parameter contains the raw number value\r\n    bool number_float(number_float_t, const std::string&);\r\n\r\n    // a string value was read\r\n    bool string(const std::string&);\r\n\r\n    // the beginning of an object was read\r\n    // binary formats may report the number of elements\r\n    bool start_object(std::size_t elements);\r\n\r\n    // an object key was read\r\n    bool key(const std::string&);\r\n\r\n    // the end of an object was read\r\n    bool end_object();\r\n\r\n    // the beginning of an array was read\r\n    // binary formats may report the number of elements\r\n    bool start_array(std::size_t elements);\r\n\r\n    // the end of an array was read\r\n    bool end_array();\r\n\r\n    // a binary value was read\r\n    // examples are CBOR type 2 strings, MessagePack bin, and maybe UBJSON array<uint8t>\r\n    bool binary(const std::vector<uint8_t>& vec);\r\n\r\n    // a parse error occurred\r\n    // the byte position and the last token are reported\r\n    bool parse_error(int position, const std::string& last_token);\r\n};\r\n```\r\n\r\nSome remarks:\r\n\r\n- All functions return a `bool`: `true` if the parser should continue or `false` if the parser should stop processing the input.\r\n- The proposal covers parsing of JSON, but also of CBOR, MessagePack, and UBJSON. Therefore, it contains extensions like array or object sizes as well as a binary type which do not occur when parsing JSON.\r\n- The idea is that the user would implement the above struct (we need to discuss whether we make all functions virtual, define a default implementation, etc.) and pass it to new parse functions, e.g. `void parse_json(SAX &sax);` or `void parse_ubjson(SAX &sax);`.\r\n\r\nWhat do you think?"}}
{"actor":{"display_login":"nlohmann"}}