Skip to content

Upgrading serde_json 0.9 to 1

Breaking0.9.10 → 1.0.154Breaking8New62Changed37Fixed43Other15

BreakingUpgrade verdict

8 breaking changes.

  • If your Deserialize code asks the deserializer for one type but expects another, it may stop working.
  • Reading a stream of JSON values now only works when the values are arrays or objects, not bare values like true or numbers.
  • The ToJson trait is gone, so code using it must switch to the to_value function.
  • You can no longer deserialize from an iterator of byte results; read from a reader instead.
Top 3 of 8 that need code or config changes

Requires Rust 1.71 from 1.0.150 (none stated before).

Breaking8
serde_json now instantiates only the expected Visitor methods, so code relying on a wrong deserialize hint may no longer deserialize successfully.
DeserializeDeserializerVisitordeserialize_u64deserialize_anyvisit_str
StreamDeserializer now only supports arrays and objects, no longer deserializing arbitrary JSON values.
StreamDeserializer
Removes the ToJson trait; use serde_json::to_value instead.
ToJsonserde_json::to_value
Removes support for deserializing from Iterator<Item = io::Result<u8>>; use serde_json::from_reader instead.
serde_json::from_reader
Removes the From<io::Error> conversion for serde_json::Error.
serde_json::Errorio::Error
Formatter trait methods now return io::Result instead of serde_json::Result.
Formatterio::Resultserde_json::Result
Formatter::write_string_fragment now receives &str instead of &[u8].
Formatter::write_string_fragment
The writer argument is now passed by value to serde_json::to_writer; passing &mut W still works.
serde_json::to_writer