Better typechecking on JSON input.

should fix #4