I just (minutes ago!) found your library, and I think it can also be used to parse truncated JSON: Parsing truncated (i.e. invalid) JSON. Is that an expected use case?
I miss something which combines peek()
and ValueType
into next_value()
, i.e. moving this block into the library and adding a Value
enum which can contain the String, bool, null, etc.
match j.peek() {
Ok(ValueType::String) => { j.next_string(); }
Ok(ValueType::Number) => { j.next_number_as_str(); }
Ok(_) => todo!(),
Err(e) => return Err(e),
};
This Value
would be similar to serde_json::Value
, but with no content in the Array and Object/Map cases. Maybe also copy the Number type so the decision between u8, i64 or f64 etc. can be made later. Or store it as next_number_as_str()
would.
Also, this library seems to panic too much, and in functions which already return Result
. Maybe the panic when peek()
-ing when only end_object()
is allowed could become a specific "expected ..." error or even ValueType::MustBeEndObject
?