I have been searching for how I would be able to work with JSON files and Liquid. What I found was a suggestion to create a metafield for it therefore I would be able to work with the JSON, in liquid like an object, enabling me to loop through it for instance.
I need to make this JSON accessible anywhere in my store. With that in mind, I would like to know if it would be possible to add a metafield to the store itself?
Something like this: {{ store.metafields.information.burn_temperature.value }}
Another idea would be adding a JSON metafield to the pages of the store. That would work, but the problem is that I would have to go to each store page and add the JSON file.
Will work, and keep in mind .value is getting the whole content-value while in liquid now with metafield-defintions(mfdfs) of type json you can access the json object properties too.
The shop resources and the namespace and key your describing will all work.
You will want to use an app to manage metafields on the shop resourcetype as they are not presented in the UI like other metafield definitions /admin/metafields.
Keep in mind there should also be a max size limit on the JSON content size, offhand I don’t know if the limits have change and the docs love to omit explicit factual roadblocks.
This can be resolved in two various ways, you can either create a liquid variable that you can access in the script and render the details accordingly, or else you can use Shop metafield for setting something globally.
The below code is for setting an array of objects having different details using liquid and script.
{% capture pageDetails %}
[
{“id”: 101, “fname”: “Your first name”, “lname”: “your last name”},
{“id”: 102, “fname”: “Your first name 2”, “lname”: “your last name2”}
]
{% endcapture %}
Hope this helps, let us know if you need any other help.