culturekings / shopify-json-parser

Shopify Liquid snippets to parse a JSON string to local variables - Unsupported April 2021
94 stars 21 forks source link

Multiple call #5

Open BarryCarlyon opened 6 years ago

BarryCarlyon commented 6 years ago

Consider this:

{% for variant in product.variants %}
{% assign test = variant.sku %}

    {%- capture json_error -%}
        {%- include 'json_decode' jd__namespace:test jd__data:variant.metafields.sitestock.warehouse -%}
    {%- endcapture -%}
{% endfor %}

This results in the "second" call to json_decode to have the first key appended to the last key.

Something like:

whstock.display.manchester
whstock.display.leeds
whstock.display__keys
whstock.display__values
whstock.display
whstock.inventory.manchester
whstock.inventory.leeds
whstock.inventory__keys
whstock.inventory__values
whstock.inventory
whstock.bin.manchester
whstock.bin.leeds
whstock.bin__keys
whstock.bin__values
whstock.bin
whstock__keys
whstock__values
whstock
whstock__keys
whstock__valueswhstock.display.manchester
whstock.display.leeds
whstock.display__keys
whstock.display__values
whstock.display
whstock.inventory.manchester
whstock.inventory.leeds
whstock.inventory__keys
whstock.inventory__values
whstock.inventory
whstock.bin.manchester
whstock.bin.leeds
whstock.bin__keys
whstock.bin__values
whstock.bin
whstock__keys
whstock__values
whstock
whstock__keys
whstock__values

With

whstock__valueswhstock.display.manchester

Being the faulty key.

The first "item" in the JSON is having it's key trashed. I'm gonna see if I can find the fault and fix it with a PR. But opening this to track as we go

BarryCarlyon commented 6 years ago

Input json:

{"display":{"manchester":"901","leeds":"1"},"inventory":{"manchester":"901","leeds":"1"},"bin":{"manchester":"Basement","leeds":""}}