JSON array to GraphQL variable

Hi, I’m struggling with passing a JSON array through to a Shopify GraphQL request.

Example array

{
    "page_of_records": [
        {
            "record": {
                "prefixedShopifyVariantIds": [
                    "gid://shopify/ProductVariant/39828607631446",
                    "gid://shopify/ProductVariant/39828607631447"
                ]
            }
        }
    ]
}

In the example below I have put “' ‘ ‘ “ around the handlebars to get a result in the preview.

Manually entering the below works, but I can’t seem for it to parse {{{jsonSerialize record.prefixedShopifyVariantIds}}}

{
    "ids": [
        "gid://shopify/ProductVariant/39828607631446",
        "gid://shopify/ProductVariant/39828607631447"
    ]
}

Can anyone point me in the right direction?

Use {{{jsonSerialize record.prefixedShopifyVariantIds}}} and then remove the double quotes and single quotes around it.

Thanks @tylerlamparter

Setting the variable like you suggested produces the following error.

{
"ids":{{{jsonSerialize record.prefixedShopifyVariantIds}}}
}
[
  {
    "code": "handlebars_template_parse_error",
    "message": "Failed to generate request body from template: {\"query\":\"query GetVariants($ids: [ID!]!) {\\r\\n  nodes(ids: $ids) {\\r\\n    ... on ProductVariant {\\r\\n      id\\r\\n      inventoryItem {\\r\\n        id\\r\\n      }\\r\\n    }\\r\\n  }\\r\\n}\",\"variables\":\"{\\\"ids\\\":{{{jsonSerialize record.prefixedShopifyVariantIds}}}}\"}. Details: Parse error on line 1:\n...xedShopifyVariantIds}}}}\"}\n-----------------------^\nExpecting 'CLOSE_UNESCAPED', 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'CLOSE_RAW_BLOCK'.",
    "occurredAt": 1757631367699,
    "resolved": false,
    "source": "resource"
  }
]

Just tested this myself and it is a bug. I've logged it internally, but if you make a support ticket, they can link your ticket to the internal one to automatically get updates on when this is fixed.

1 Like

Thanks @tylerlamparter

Can you try with only two braces and no quotes?

@friendoftuesday just seeing this and confirmed no quotes and only 2 curly braces work.

{"ids": {{jsonSerialize settings.export.ids}} }