Hi,
I came across [Feature]: Add support for JSON file format in assets in theme app extensions · Issue #1962 · Shopify/cli · GitHub but did not find any documentation on how to include json files in assets. Do I add data.json in my assets folder and added in the schema below or any other way? Thank you.
{% schema %}
{
“name”: “Testing”,
“target”: “body”,
“javascript”: “main.js”,
“stylesheet”: “styles.css”,
“settings”:
}
{% endschema %}
Hi Gaurav,
As far as I understand, you should simply be able to add a .json
file to the assets folder and deploy / update the app. Is this not working for you?
Hi Liam,
So this is what I did:
-
Add a data.json file in the assets folder
-
Start Shopify dev
-
Try to read it via javascript using fetch:
fetch('./data.json')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ’ + response.statusText);
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error(‘There was a problem with the fetch operation:’, error);
});
- This threw an error saying file not found
- Try to find the file in the Sources tab in browser but couldnt find the data.json file
- Did Shopify Deploy and cant find this file in production sites Sources tab in my extension files directory as well.
I was wondering if I am doing the right thing? or is there something else to be done?
Figured it out…
So JSON file in asset has to be reference in the main liquid files in blocks for them to be loaded.