Validate JSON to avoid crashing.

Fixes #19.