{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize/issues/50","repository_url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize","labels_url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize/issues/50/comments","events_url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize/issues/50/events","html_url":"https://github.com/rust-lang-nursery/rustc-serialize/issues/50","id":56785271,"number":50,"title":"Better Option support in Hash/Objects","user":{"login":"kali","id":53657,"avatar_url":"https://avatars.githubusercontent.com/u/53657?v=3","gravatar_id":"","url":"https://api.github.com/users/kali","html_url":"https://github.com/kali","followers_url":"https://api.github.com/users/kali/followers","following_url":"https://api.github.com/users/kali/following{/other_user}","gists_url":"https://api.github.com/users/kali/gists{/gist_id}","starred_url":"https://api.github.com/users/kali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kali/subscriptions","organizations_url":"https://api.github.com/users/kali/orgs","repos_url":"https://api.github.com/users/kali/repos","events_url":"https://api.github.com/users/kali/events{/privacy}","received_events_url":"https://api.github.com/users/kali/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-02-06T08:43:29Z","updated_at":"2017-02-02T06:01:30Z","closed_at":null,"body":"It would be nice, in JSON ser/deser to map an optional key in a json objet to an Option<_> field in a struct. \"None\" would map from/to the absence of the key/value pair in the json object.\n\nAs far as I can tell, the current implementation makes it non-trivial as values are serialized separately from their key.\n"},"comment":{"url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize/issues/comments/276875760","html_url":"https://github.com/rust-lang-nursery/rustc-serialize/issues/50#issuecomment-276875760","issue_url":"https://api.github.com/repos/rust-lang-nursery/rustc-serialize/issues/50","id":276875760,"user":{"login":"dtolnay","id":1940490,"avatar_url":"https://avatars.githubusercontent.com/u/1940490?v=3","gravatar_id":"","url":"https://api.github.com/users/dtolnay","html_url":"https://github.com/dtolnay","followers_url":"https://api.github.com/users/dtolnay/followers","following_url":"https://api.github.com/users/dtolnay/following{/other_user}","gists_url":"https://api.github.com/users/dtolnay/gists{/gist_id}","starred_url":"https://api.github.com/users/dtolnay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtolnay/subscriptions","organizations_url":"https://api.github.com/users/dtolnay/orgs","repos_url":"https://api.github.com/users/dtolnay/repos","events_url":"https://api.github.com/users/dtolnay/events{/privacy}","received_events_url":"https://api.github.com/users/dtolnay/received_events","type":"User","site_admin":false},"created_at":"2017-02-02T06:01:30Z","updated_at":"2017-02-02T06:01:30Z","body":"In Serde, deserialization supports this by default:\r\n\r\n```rust\r\n#[macro_use]\r\nextern crate serde_derive;\r\nextern crate serde_json;\r\n\r\n#[derive(Deserialize, Debug)]\r\nstruct S {\r\n    opt: Option<String>,\r\n}\r\n\r\nfn main() {\r\n    println!(\"{:?}\", serde_json::from_str::<S>(\"{}\").unwrap());\r\n}\r\n```\r\n\r\nAnd serialization treats None as null by default but you can use an attribute to selectively omit the entire map entry in the case of None:\r\n\r\n```rust\r\n#[macro_use]\r\nextern crate serde_derive;\r\nextern crate serde_json;\r\n\r\n#[derive(Serialize)]\r\nstruct S {\r\n    #[serde(skip_serializing_if = \"Option::is_none\")]\r\n    opt: Option<String>,\r\n}\r\n\r\nfn main() {\r\n    println!(\"{}\", serde_json::to_string(&S { opt: None }).unwrap());\r\n}\r\n```"}}
{"actor":{"display_login":"dtolnay"}}