json-rust icon indicating copy to clipboard operation
json-rust copied to clipboard

Allow parsing from `std::io::Read`

Open konstin opened this issue 7 years ago • 2 comments

Currently, simply reading a file to a JsonValue involves quite some boilerplate:

let mut contents = String::new();
let mut file = File::open(some_path)?;
file.read_to_string(&mut contents)?;
let json = json::parse(&contents)?;

This could be hugely improved by allowing parsing directly from a std::io::Read:

let json = json::parse(File::open(some_path)?)?;

konstin avatar Apr 08 '17 21:04 konstin

It may be useful to provide an load() convenience wrapper specifically for such task as it may be in high demand.

imp avatar Apr 09 '17 06:04 imp

alternative:

https://docs.rs/serde_json/latest/serde_json/fn.from_reader.html

89z avatar Sep 10 '22 22:09 89z