You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a JSON packet that has multibyte, i.e. non-ASCII, characters, then errors reported related to that packet such as the data error I trigger below will report a higher column number than you would see in a text editor, likely a byte offset.
This renders the reported column number useless in instances of non-English data or emojis and is magnified if the data is a large single-line packet, which isn't uncommon.
use serde::{Deserialize,Serialize};fnmain(){// `'not a number'` is at line 1 column 66let json = "{\"my_ascii_chars\": \"asdf\", \"my_utf8_chars\": \"/ˈa.ʎo/\", \"my_int\": \"not a number\"}";let test:Option<ColumnTest> = match serde_json::from_str::<ColumnTest>(json){Ok(_) => panic!("no error generated"),Err(error) => {println!("{error}");assert_eq!(error.column(), 66);None}};}#[derive(Debug,Serialize,Deserialize)]structColumnTest{my_ascii_chars:String,my_utf8_chars:String,my_int:u32,}
Output:
invalid type: string "not a number", expected u32 at line 1 column 81
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `81`,
right: `66`', src/main.rs:10:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The text was updated successfully, but these errors were encountered:
If you have a JSON packet that has multibyte, i.e. non-ASCII, characters, then errors reported related to that packet such as the data error I trigger below will report a higher column number than you would see in a text editor, likely a byte offset.
This renders the reported column number useless in instances of non-English data or emojis and is magnified if the data is a large single-line packet, which isn't uncommon.
Output:
The text was updated successfully, but these errors were encountered: