Parse JSON responses and compare them as objects

This allows differences in spacing and differences in the order of properties in the returned JSON.

Also fixed a few JavaScript issues (missing `var`, reserved words as object keys).