Does serde not consider [] to be valid json?

Does serde not consider [] to be valid json?
I am playing with warp and reqwest and I just tried to run

let mut resp = client.get("https://localhost:3030/todos/")
    .send()?;
println!("{:#?}", resp.text()?);
let resp = resp.json()?;

which gave me

"[]"
Error: Error(Json(Error("EOF while parsing a value", line: 1, column: 0)))

Shouldn't that work?

resp.text() reads the entire body off the network - it's not there any more when you call resp.json().

2 Likes

Okay, that may be true but I tried it without the extra printing of the text first and it failed with the same error.

No, it didn't. I'm a liar.

The error before was:

Error: Error(Json(Error("invalid type: sequence, expected unit", line: 1, column: 1)))

Sorry, didn't notice the change.

What type are you asking resp.json() to return to you?

I didn't specify it.

let resp = client.get("https://localhost:3030/todos/")
    .send()?.json()?;

println!("{:#?}", resp);

Good idea. Apparently, it works with resp: Vec<String>.

So, apparently it cannot correctly infer the type and then decides the type should be unit and then complains because the JSON it parses doesn't match that type.
Ouch. :poop:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.