You are not logged in.
Hi Guys,
I am noticing that json_serde::Value is not able to convert a string to json, if String dont have doubel quotes around them.
e.g.
use serde_json::{Result, Value};
fn main() -> Result<()>{
let raw_text = r##"{
"url" : https://www.google.com
}"##;
println!("{}",raw_text);
let v: Value = serde_json::from_str(raw_text)?;
println!("{}", v["url"]);
Ok(())
}Output :
json git:master ❯❯❯ cargo run ✭
Compiling json v0.1.0 (/home/d/Documents/RustScripts/json)
Finished dev [unoptimized + debuginfo] target(s) in 0.21s
Running `target/debug/json`
{
"url" : https://www.google.com
}
Error: Error("expected value", line: 2, column: 19)Any tips to handle this scenario will be useful.
Either I can add double quotes around the String where its missing or I need to find a way to deserialize the json.
Thanks ![]()
Keep Calm, And Enjoy Life ![]()
Offline
The Problem is that you are trying to parse invalid json and the library yelling at you for doing so. A string in json is required to be in double quotes.
Either I can add double quotes around the String where its missing or I need to find a way to deserialize the json.
If your original data set does not have the right quoting you need to fix up your data set first. Is there a reason why you cant add the quotation marks?
Edit: just to prevent any misunderstandings, the string in question is the https://www.google.com
Last edited by lmn (2022-06-13 12:11:52)
Offline
@Debasish Patra
You accidentally hit report instead of reply:
Thanks, even I was wondering the same. Why only url does not have quotes around them. It looked like a bug on the server, which has been corrected. Thanks for the explanation. I will close this .
Please mark the topic as [SOLVED] by editing the thread title.
Offline