#serialization #json-parser #serde-default #option-like #undefined #serde-json #deserialize

js_option

An Option-like type with separate null and undefined variants

3 unstable releases

0.2.0 Sep 14, 2025
0.1.1 Jun 18, 2022
0.1.0 May 10, 2021

#374 in Encoding

Download history 7122/week @ 2025-10-11 7831/week @ 2025-10-18 7794/week @ 2025-10-25 8275/week @ 2025-11-01 7981/week @ 2025-11-08 9103/week @ 2025-11-15 9197/week @ 2025-11-22 9785/week @ 2025-11-29 12490/week @ 2025-12-06 10356/week @ 2025-12-13 5568/week @ 2025-12-20 5325/week @ 2025-12-27 8643/week @ 2026-01-03 8423/week @ 2026-01-10 12963/week @ 2026-01-17 13257/week @ 2026-01-24

44,174 downloads per month
Used in 66 crates (7 directly)

MIT license

10KB
138 lines

js_option

This crate provides a type JsOption that is very similar to the standard library's Option type except that it has three variants:

  • Some(value): Like Option::Some
  • Null: Explicitly not some value
  • Undefined: Implicitly not some value

This type can be useful when you want to deserialize JSON to a Rust struct and not loose information: A regular Option deserializes to None from both an explicit null or a missing field (this is due to special casing of Option in the Deserialize and Serialize derive macros, for other types a missing field will make deserialization fail unless there is a #[serde(skip)], #[serde(skip_deserializing)] or #[serde(default)] attribute).

Example:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct MyStruct {
    #[serde(default, skip_serializing_if = "JsOption::is_undefined")]
    my_field: JsOption<String>,
}

License

MIT

Dependencies

~120KB