Modified the trends data function to deal with JSON data returned by API call