{"action":"created","issue":{"url":"https://api.github.com/repos/scala-js/scala-js/issues/2344","repository_url":"https://api.github.com/repos/scala-js/scala-js","labels_url":"https://api.github.com/repos/scala-js/scala-js/issues/2344/labels{/name}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/2344/comments","events_url":"https://api.github.com/repos/scala-js/scala-js/issues/2344/events","html_url":"https://github.com/scala-js/scala-js/issues/2344","id":149675840,"number":2344,"title":"Suggesting `NullOr` similar to `UndefOr` for JS-structures","user":{"login":"lastsys","id":9558188,"avatar_url":"https://avatars.githubusercontent.com/u/9558188?v=3","gravatar_id":"","url":"https://api.github.com/users/lastsys","html_url":"https://github.com/lastsys","followers_url":"https://api.github.com/users/lastsys/followers","following_url":"https://api.github.com/users/lastsys/following{/other_user}","gists_url":"https://api.github.com/users/lastsys/gists{/gist_id}","starred_url":"https://api.github.com/users/lastsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lastsys/subscriptions","organizations_url":"https://api.github.com/users/lastsys/orgs","repos_url":"https://api.github.com/users/lastsys/repos","events_url":"https://api.github.com/users/lastsys/events{/privacy}","received_events_url":"https://api.github.com/users/lastsys/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-04-20T06:51:50Z","updated_at":"2016-05-17T04:20:10Z","closed_at":null,"body":"When handling JSON-objects some fields can contain `null` values. It would be nice to have such values parsed automatically to `Option` where `null` represents `None`.\r\n\r\nExample:\r\n\r\n```json\r\n{\r\n  \"name\": null\r\n}\r\n```\r\n\r\ncould be defined as\r\n\r\n```scala\r\ntrait MyObj extends js.Object {\r\n  val name: js.NullOr[String]\r\n}\r\n```\r\n\r\nwhich means that when accessed we get\r\n\r\n```scala\r\nval name: Option[String] = myObj.name.toOption\r\n```\r\n\r\nNot sure what to write if, for some reason, a field can be either `undefined`, `null` or `String`.\r\n"},"comment":{"url":"https://api.github.com/repos/scala-js/scala-js/issues/comments/219615711","html_url":"https://github.com/scala-js/scala-js/issues/2344#issuecomment-219615711","issue_url":"https://api.github.com/repos/scala-js/scala-js/issues/2344","id":219615711,"user":{"login":"lastsys","id":9558188,"avatar_url":"https://avatars.githubusercontent.com/u/9558188?v=3","gravatar_id":"","url":"https://api.github.com/users/lastsys","html_url":"https://github.com/lastsys","followers_url":"https://api.github.com/users/lastsys/followers","following_url":"https://api.github.com/users/lastsys/following{/other_user}","gists_url":"https://api.github.com/users/lastsys/gists{/gist_id}","starred_url":"https://api.github.com/users/lastsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lastsys/subscriptions","organizations_url":"https://api.github.com/users/lastsys/orgs","repos_url":"https://api.github.com/users/lastsys/repos","events_url":"https://api.github.com/users/lastsys/events{/privacy}","received_events_url":"https://api.github.com/users/lastsys/received_events","type":"User","site_admin":false},"created_at":"2016-05-17T04:20:10Z","updated_at":"2016-05-17T04:20:10Z","body":"Nice approach. Would that work for `UndefOr` as well?\r\nThe first `NullOr` approach has been working very well for me and I have even added an `EmptyObjectOr` which maps to `jQuery.isEmptyObject()`.\r\n\r\nMany people would argue that these things belong in a serialization library, however, when you need to work with raw JS-objects when writing bindings for existing libraries it is helpful to have some kind of low level \"serialization\".\r\n\r\nI suggest that SJS gets an official facade tool library where best practices for handling cases like this are collected. You are right that these thing doesn't belong in the core language."}}