function fetch(url, useJson = true) { const queryURL = $.NSURL.URLWithString(url); const requestData = $.NSData.dataWithContentsOfURL(queryURL); const requestString = $.NSString.alloc.initWithDataEncoding( requestData, $.NSUTF8StringEncoding, ).js; if (useJson) { return JSON.parse(requestString); } else { return requestString; } } console.log(fetch("https://melaniekat.com/gifs/api"))