{"action":"created","issue":{"url":"https://api.github.com/repos/bolerio/mjson/issues/20","repository_url":"https://api.github.com/repos/bolerio/mjson","labels_url":"https://api.github.com/repos/bolerio/mjson/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/bolerio/mjson/issues/20/comments","events_url":"https://api.github.com/repos/bolerio/mjson/issues/20/events","html_url":"https://github.com/bolerio/mjson/issues/20","id":143711019,"number":20,"title":"Why json.at() returns null instead of an object?","user":{"login":"leolux","id":5385814,"avatar_url":"https://avatars.githubusercontent.com/u/5385814?v=3","gravatar_id":"","url":"https://api.github.com/users/leolux","html_url":"https://github.com/leolux","followers_url":"https://api.github.com/users/leolux/followers","following_url":"https://api.github.com/users/leolux/following{/other_user}","gists_url":"https://api.github.com/users/leolux/gists{/gist_id}","starred_url":"https://api.github.com/users/leolux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leolux/subscriptions","organizations_url":"https://api.github.com/users/leolux/orgs","repos_url":"https://api.github.com/users/leolux/repos","events_url":"https://api.github.com/users/leolux/events{/privacy}","received_events_url":"https://api.github.com/users/leolux/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-26T14:39:18Z","updated_at":"2016-03-26T14:47:00Z","closed_at":null,"body":"The following code produces a NullPointerException:\r\n\r\n    Json json = Json.object();\r\n    String value = json.at(\"notAvailable\").asString();\r\n\r\nWhat is the advantage of json.at(\"...\") returning null instead of a json object? I would have expected the java null value from the _asString()_ method.\r\n\r\nThe method Json.read() for example will never return the actual Java null. Could this also be done for the method json.at(\"...\")?"},"comment":{"url":"https://api.github.com/repos/bolerio/mjson/issues/comments/201838326","html_url":"https://github.com/bolerio/mjson/issues/20#issuecomment-201838326","issue_url":"https://api.github.com/repos/bolerio/mjson/issues/20","id":201838326,"user":{"login":"bolerio","id":918099,"avatar_url":"https://avatars.githubusercontent.com/u/918099?v=3","gravatar_id":"","url":"https://api.github.com/users/bolerio","html_url":"https://github.com/bolerio","followers_url":"https://api.github.com/users/bolerio/followers","following_url":"https://api.github.com/users/bolerio/following{/other_user}","gists_url":"https://api.github.com/users/bolerio/gists{/gist_id}","starred_url":"https://api.github.com/users/bolerio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolerio/subscriptions","organizations_url":"https://api.github.com/users/bolerio/orgs","repos_url":"https://api.github.com/users/bolerio/repos","events_url":"https://api.github.com/users/bolerio/events{/privacy}","received_events_url":"https://api.github.com/users/bolerio/received_events","type":"User","site_admin":false},"created_at":"2016-03-26T14:47:00Z","updated_at":"2016-03-26T14:47:00Z","body":"I need to setup of a discussion forum/mailing list for question like this :) I looked at the Discuss project here on Github and it looks really nice, but requires a Docker instance to be placed on a cloud somewhere, heavy stuff...\r\n\r\nAnyway, json.at(name) will return a Java null instead of a Json.nil() for a missing property because one must be able to differentiate between the two. If json.at(\"notAvailable\") returned a Json.nil(), it would mean the property is there with a value null. json.at() will return Java null if and only if json.has() return false for the same name. Default values were introduced for cases like this:\r\n\r\njson.at(\"notAvailable\", \"\").asString() // will return empty string\r\njson.at(\"notAvailable\", null).asString() // will throw an UnsupportedOperationException because a null cannot be treated as a string in JSON.\r\n"}}