Changed the JSON "tpe" field to "$type" and fixed the tests.

A re-targeted pull request for #113 (#64)