Add JSON compat library

- Removes need for global constant definitions
- Allows easier handling of JSON parse errors
Use JSON compat everywhere