maciejhirsz / json-rust

JSON implementation in Rust
Apache License 2.0
563 stars 63 forks source link

Allow extra characters at end #176

Open Timmmm opened 4 years ago

Timmmm commented 4 years ago

It would be really helpful for my use case if there were a way to allow data after the JSON, and to report how much JSON was actually read.

For example if I have data like this:

{"type": "string", "length": 5}Hello

It would return the JSON data, plus a length of 31 (up to the }).

Looks like this would be easy something along the lines of this commit which I have not tested (or even compiled).

Bit of a weird use case!

maciejhirsz commented 4 years ago

By default, and per spec, any extra characters at the end are to be considered errors, however I think I can add that as an option with a generic on the parser.

This could also make it possible to have an iterator parser, eg. for log formats that print json objects on new lines.