json: Fix bug.

Check for the end of file has to placed before reading.