Get static JSON file from weweb asset file

Hi folks,

If I’m storing a static json file within weweb assets to use as a collection. What is the recommended method to call that file?

I tried multiple code snippets using JavaScript as the source, however, although it returns a ‘successfully fetched’ message it says the object is empty.

Inserting the url into a REST API call successfully returns the data.

I’m wondering what the best method is, and if JavaScript is the recommendation, what do i need to fix in the javascript code to make that work?


You need to return something from your code.
You may want to use async/await.

Thanks for your help @dorilama

The code below is now working based on the response within the chrome console, but the weweb collection is still showing as empty. ??

First time trying to configure a collection like this so I’m very confused.

Any reason why you use both fetch and axios?
You are returning data from axios, this is your collection data, and logging the data from fetch.
From your screenshot I can see that the logged data is an array, so probably for your collection data.results is empty.
Have you tried to return only

Appreciate your responses @dorilama

The short answer is I’m just trying to work it out as a go so very limited knowledge about the code at the moment.

The frustrating thing is, I just returned to using the sample javascript code provided during configuration and now it works. And, that is after previously getting an empty response, and Access-Control errors. So now I’m confused as to what was happening before.