jsonc-parser icon indicating copy to clipboard operation
jsonc-parser copied to clipboard

Deserialize to concrete type with error line/column

Open probablykasper opened this issue 2 years ago • 1 comments

I'd really like a way to deserialize into a struct while seeing the line/column of errors when there's an invalid type.

With serde_json::from_str I parse a string directly into a struct:

let settings_str = fs::read_to_string(&file_path).unwrap();
serde_json::from_str(&settings_str).unwrap()

And that shows the line/column. But with parse_to_serde_value() & serde_json::from_value, you lose that:

thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("invalid type: boolean true, expected struct Example", line: 0, column: 0)', src/settings.rs:32:40

probablykasper avatar May 30 '23 19:05 probablykasper

I think you pasted the same output twice, they both show line: 0, column: 0.

tv42 avatar Nov 03 '23 19:11 tv42