{"action":"created","issue":{"url":"https://api.github.com/repos/stedolan/jq/issues/873","labels_url":"https://api.github.com/repos/stedolan/jq/issues/873/labels{/name}","comments_url":"https://api.github.com/repos/stedolan/jq/issues/873/comments","events_url":"https://api.github.com/repos/stedolan/jq/issues/873/events","html_url":"https://github.com/stedolan/jq/issues/873","id":97574956,"number":873,"title":"Unexpected \"empty\" behaviour (reduce does not like it when the update expression backtracks)","user":{"login":"borisovg","id":3171327,"avatar_url":"https://avatars.githubusercontent.com/u/3171327?v=3","gravatar_id":"","url":"https://api.github.com/users/borisovg","html_url":"https://github.com/borisovg","followers_url":"https://api.github.com/users/borisovg/followers","following_url":"https://api.github.com/users/borisovg/following{/other_user}","gists_url":"https://api.github.com/users/borisovg/gists{/gist_id}","starred_url":"https://api.github.com/users/borisovg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borisovg/subscriptions","organizations_url":"https://api.github.com/users/borisovg/orgs","repos_url":"https://api.github.com/users/borisovg/repos","events_url":"https://api.github.com/users/borisovg/events{/privacy}","received_events_url":"https://api.github.com/users/borisovg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/stedolan/jq/labels/feature%20request","name":"feature request","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/stedolan/jq/milestones/7","html_url":"https://github.com/stedolan/jq/milestones/1.6%20release","labels_url":"https://api.github.com/repos/stedolan/jq/milestones/7/labels","id":882049,"number":7,"title":"1.6 release","description":"","creator":{"login":"nicowilliams","id":604851,"avatar_url":"https://avatars.githubusercontent.com/u/604851?v=3","gravatar_id":"","url":"https://api.github.com/users/nicowilliams","html_url":"https://github.com/nicowilliams","followers_url":"https://api.github.com/users/nicowilliams/followers","following_url":"https://api.github.com/users/nicowilliams/following{/other_user}","gists_url":"https://api.github.com/users/nicowilliams/gists{/gist_id}","starred_url":"https://api.github.com/users/nicowilliams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicowilliams/subscriptions","organizations_url":"https://api.github.com/users/nicowilliams/orgs","repos_url":"https://api.github.com/users/nicowilliams/repos","events_url":"https://api.github.com/users/nicowilliams/events{/privacy}","received_events_url":"https://api.github.com/users/nicowilliams/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":4,"state":"open","created_at":"2014-11-26T23:57:47Z","updated_at":"2015-07-28T06:22:09Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2015-07-27T22:56:30Z","updated_at":"2015-07-28T16:58:04Z","closed_at":null,"body":"This could well be me misunderstanding the way `empty` works but this is unexpected:\r\n\r\n````\r\nborisov@deli:~ $ echo '{\"key1\": {\"attr1\": \"foo\"}, \"key2\": {\"attr1\": \"foo\", \"attr2\": \"bar\"}}' | jq '.[].attr2 |= if . then \"bar\" else empty end'                               \r\nnull\r\n````\r\n\r\nExpected something like this (but without .key1.attr2 set to \"null\"):\r\n\r\n````\r\nborisov@deli:~ $ echo '{\"key1\": {\"attr1\": \"foo\"}, \"key2\": {\"attr1\": \"foo\", \"attr2\": \"bar\"}}' | jq '.[].attr2 |= if . then \"bar\" else . end'\r\n{\r\n  \"key1\": {\r\n    \"attr1\": \"foo\",\r\n    \"attr2\": null\r\n  },\r\n  \"key2\": {\r\n    \"attr1\": \"foo\",\r\n    \"attr2\": \"bar\"\r\n  }\r\n}\r\n````\r\njq version: jq-1.5rc2"},"comment":{"url":"https://api.github.com/repos/stedolan/jq/issues/comments/125678811","html_url":"https://github.com/stedolan/jq/issues/873#issuecomment-125678811","issue_url":"https://api.github.com/repos/stedolan/jq/issues/873","id":125678811,"user":{"login":"nicowilliams","id":604851,"avatar_url":"https://avatars.githubusercontent.com/u/604851?v=3","gravatar_id":"","url":"https://api.github.com/users/nicowilliams","html_url":"https://github.com/nicowilliams","followers_url":"https://api.github.com/users/nicowilliams/followers","following_url":"https://api.github.com/users/nicowilliams/following{/other_user}","gists_url":"https://api.github.com/users/nicowilliams/gists{/gist_id}","starred_url":"https://api.github.com/users/nicowilliams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicowilliams/subscriptions","organizations_url":"https://api.github.com/users/nicowilliams/orgs","repos_url":"https://api.github.com/users/nicowilliams/repos","events_url":"https://api.github.com/users/nicowilliams/events{/privacy}","received_events_url":"https://api.github.com/users/nicowilliams/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T16:58:04Z","updated_at":"2015-07-28T16:58:04Z","body":"BTW, we don't document what happens when the update expr of `reduce` or `foreach` backtracks.  We should first decide what we want that to be."}}