Added JSON encoding functionality.