kirchner-trevor / vscode-shopify-liquid-preview

19 stars 6 forks source link

Doesn't support JSON property names with spaces #13

Open alainbryden opened 4 years ago

alainbryden commented 4 years ago

Thanks for the great extension. I've stumbled on the following omission:

Given the input JSON:

{
    "EntityType": "FxRate",
    "Rates": [{
        "Currency Code": "AED",
        "Currency Name": "UNITED ARAB EMIRATES DIRHAM",
        "FX Rate": 3.672900000,
        "Fx Rate Set Id": "MXR2020M05"
    }, {
        "Currency Code": "ZWR",
        "Currency Name": "ZIMBABWE DOLLAR",
        "FX Rate": 25.000000000,
        "Fx Rate Set Id": "MXR2020M05"
    }]
}

The following liquid template should work (does work using other implementations):

{
    "FXRateSetName": "{{ Rates[0]["Fx Rate Set Id"] }}",
    "isDefault": "true", 
    "baseCurrencyCode": "USD",
    "FXRates": [
        {%- for fxrate in Rates -%}
        {
            "currencyCode": "{{ fxrate["Currency Code"] }}",
            "exchangeRate": "{{ fxrate["FX Rate"] }}",
        }{%- if forloop.last == false -%},{%- endif %}
        {%- endfor -%}
    ]
}

But I'm seeing the following error from the extension:

Command 'Shopify Liquid: Open Preview to the Side' resulted in an error (cannot open shopify-liquid-preview:Preview%20sampleExactMaxPayload%20-%20CreateFxRate.json%20%2B%20FxRate_Map.liquid?id%3D1592587377815. Detail: unbalanced ": Rates[0]["Fx, line:2, col:23)

The expected output is:

{
    "FXRateSetName": "MXR2020M05",
    "isDefault": "true", 
    "baseCurrencyCode": "USD",
    "FXRates": [
        {
            "currencyCode": "AED",
            "exchangeRate": "3.6729",
        },
        {
            "currencyCode": "ZWR",
            "exchangeRate": "25",
        }
    ]
}

I've tried a number of approaches, including using single quotes rather than double quotes around the property name, but to no avail.

Cheers,

matthijssn commented 3 years ago

Same issue here, with using a : in a field name. I've tried to wrap the fieldname with [ ], but I still get the unbalanced error.

kirchner-trevor commented 3 years ago

Hey! I'm sorry to see that you're having an issue with the extension. I haven't had much time to dedicate to it, so I was hoping someone might fork the repository.

I'll try and make some time in the next week or two to try and clean up some of these issues.

matthijssn commented 3 years ago

Hi @kirchner-trevor , just curious if you already had the time to have a look at the issue above? Thanks and stay safe!