refactored api-functions for json handling.