         (if (= (codepoint \:) (int (next-token stream)))
           key
           (throw (Exception. "JSON error (missing `:` in object)"))))
-      (if (= c (codepoint \}))
-        nil
+      (codepoint-case c
+        \} nil
+        -1 (throw (Exception. "JSON error (end-of-file inside object)"))
         (throw (Exception. (str "JSON error (non-string key in object), found `" (char c) "`, expected `\"`")))))))
 
 (defn- read-object [^PushbackReader stream options]

          (codepoint-case (int (next-token stream))
            \, (recur r)
            \} (persistent! r)
            (throw (Exception. "JSON error (missing entry in object)"))))
        (let [r (persistent! result)]
          (if (empty? r)

    (codepoint-case c
      \] []
      \, (throw (invalid-array-exception))
      -1 (throw (Exception. "JSON error (end-of-file inside array)"))
      (do (.unread stream c)
          (read-array* stream options)))))

