Serde_json doesn't parse this?

I've added a valetudo_state_watcher function to my src/ · main · thomas351 / rust-influxdb-udp-logger · GitLab

I've expected this line to get parsed and reach the innermost if:

data: [{"__class":"AttachmentStateAttribute","metaData":{},"type":"watertank","attached":false},{"__class":"AttachmentStateAttribute","metaData":{},"type":"mop","attached":false},{"__class":"StatusStateAtt
if let Ok(value) = from_str::<Value>(&line) {
	if let Some(data) = value["data"].as_str() {
		println!("Received data: {}", data);
	else {
		println!("couldn't extract data. value = {value}");
else {
	println!("couldn't parse as json, line = {line}")

But the only line I've seen so far that doesn't end up in the last else block = "couldn't parse as json," was = "11".

Why? Is the problem, that the beginning reads data: instead of "data":? Can I make it more tolerant and accept strings without double-quotes? I don't control the software creating these events..

Yes it's because that key isn't quoted and doesn't seem to be in an object.

No you can't parse not-JSON with serde_json. You'll have to use a relaxed parser such as hjson or similar JSON variant.


If it's always "data: $VALID_JSON", you could just strip the "data:" part off.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.