Shopify - Name In Variant Is Null, But Others Keys Are Not

- 1 answer

Doing this on my Shopify page:

{{ product.selected_or_first_available_variant | json }}

Yields me this JSON output.

    "id": 22061938375,
    "title": "Small / Black",
    "option1": "Small",
    "option2": "Black",
    "option3": null,
    "sku": "LSL2",
    "requires_shipping": true,
    "taxable": true,
    "featured_image": {
        "id": 14987460807,
        "product_id": 6956222919,
        "position": 1,
        "created_at": "2016-06-24T11:03:47+01:00",
        "updated_at": "2016-06-24T18:17:08+01:00",
        "src": "",
        "variant_ids": [
    "available": false,
    "name": "Long Sleeve Chantilly Lace Shimmy - Small / Black",
    "options": [
    "price": 8800,
    "weight": 454,
    "compare_at_price": null,
    "inventory_quantity": 0,
    "inventory_management": "shopify",
    "inventory_policy": "deny",
    "barcode": ""

If I then do: {{ | json }} I get: 22061938375 (correct).

However, if I try and grab another key like name with this: {{ | json }} I get null(wrong).

What on Earth is going on here? Why can I only access some keys and not all of them, even though I can see them in the full output? It's not making much sense to me.

Any help greatly appreciated.




I believe your problem is that "name" is not actually a member of variant. I'm guessing that the "name" that appears in the JSON output is dynamically generated. It is simply the concatenation of the product title and variant title.

Also using the JSON filter for this is overkill. You can do

{{ product.title }} {{ product.selected_or_first_available_variant.title }}

if you know that the product has options or something like:

{% assign currVar = product.selected_or_first_available_variant %}
{{ product.title }}{% unless currVar.title contains 'Default' %} {{ currVar.title }}{% endunless %}