Properly handle incomplete json when input is file

Fix #562