Parsing JSON into Liquid Javascript

Chanbabs
New Member
1 0 0

Hi!

We have a string variable which contains json, which is being dinamically passed in to the body of the products page. The split function wont work for us, and havnt found a good solution with json.stringify. Is there any way we can parse that json object in liquid JavaScript? 

We will be displaying the results assisiated with the variable on the products page.

 

Thanks!

0 Likes
Jason
Shopify Expert
10360 158 2003

This post doesn't relate to the Shopify Script Editor App so I'd assume you've posted this in the wrong forum section. You'll get better responses if you post in a related section so I'm going to move your post elsewhere (why).

Now as for your question, why does the data need to be stored as JSON in the first place? How complex is the data?

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
TomTranzistor
Shopify Partner
31 2 5

Hey folks, 

 

With the new JSON metafields you can parse easily JSON

{
  "faq": [
    {
      "question": "blabla ?",
      "reponse": "ouioui"
    },
    {
      "question": "blabla 2 ?",
      "reponse": "ouioui"
    },
    {
      "question": "blabla 3 ?",
      "reponse": "nono"
    }
  ]
}
<div id="shopify-section-{{block.id}}" class="container main content faq-section">
  <div class="{% if image_section %}eight{% else %} sixteen {% endif %}  columns">
      <dl class="faqAccordion">
        {% if product.metafields.my_fields['faq'] != blank %}
          {% for element in product.metafields.my_fields['faq'].value.faq %}
            <dt><button type="button" aria-controls="custom-panel-01" aria-expanded="true">{{ element['question'] }}</button></dt>
            <dd id="custom-panel-01" aria-hidden="false">
              {{ element['reponse'] }}
            </dd>
          {% endfor %}
        {% endif %}
      </dl>
  </div>
</div>

 

Let us help you - Tranzistor.tech
0 Likes