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
I'm integrating against a third-party backend and unfortunately I'm faced with the following invalid JSON:
{
"value": True
}
Using this answer, I tried implementing a function for the deserialize_with field attribute with the various visitor APIs (e.g. an obviously failed attempt on the Rust playground), but as far as I can tell, the problem is that the input is not recognized as any correct type, so none of the visitor APIs work here.
Are there any possible workarounds here that do not require implementing an entirely new Deserializer for this invalid JSON? Or am I better off manually parsing the input string? Alternatively, is there a way to implement a Deserializer that only parses the invalid JSON and forwards everything else to the Deserializer in serde_json?
Any insight is much appreciated.
The text was updated successfully, but these errors were encountered:
vimpunk
changed the title
[question] How to deserialize invalid JSON?
[question] How to deserialize invalid boolean?
Feb 4, 2020
We don't support deserializing syntactically invalid JSON. If you need to deserialize something that is not JSON, you should do it with something other than serde_json.
Some people have forked serde_json to add nonstandard features, so you could do the same and modify it to accept True.
Thanks, that works, although is more effort than my use case warrants.
A hacky solution, for anyone else having similar issues is to string replace True and False instances in the raw response string to true and false. Not perfect, since if a string contains these those will be replaced, but is perhaps an acceptable solution for a limited usecase.
I'm integrating against a third-party backend and unfortunately I'm faced with the following invalid JSON:
Using this answer, I tried implementing a function for the
deserialize_with
field attribute with the various visitor APIs (e.g. an obviously failed attempt on the Rust playground), but as far as I can tell, the problem is that the input is not recognized as any correct type, so none of the visitor APIs work here.Are there any possible workarounds here that do not require implementing an entirely new Deserializer for this invalid JSON? Or am I better off manually parsing the input string? Alternatively, is there a way to implement a Deserializer that only parses the invalid JSON and forwards everything else to the Deserializer in serde_json?
Any insight is much appreciated.
The text was updated successfully, but these errors were encountered: