Add JSON compat library

- Removes need for global constant definitions
- Allows easier handling of JSON parse errors
Use JSON compat everywhere
Merge pull request #614 from idio/feature/json-compat

JSON Compat Library