[Rebased] Fix compile errors under mingw-w64.

Rebased onto 9b6f871, because why not? But do try not to lose it this time.

Also, I got chkjson fixed while I was at it. This should give us clean builds from Jenkins as soon as it's merged.