I use Bulk Export to dump a store product inventory. My GQL includes asking for product vendor. Shopify JSONL payload when I examine the result in my text editor contains this:
"Zulu \u0026 Zephyr"
but the vendor field I get from asking for shop vendors using GQL returns to me this:
"Zulu & Zephyr"
So in my app when I compare these two strings they no longer match. What is the simple sauce to fixing this? This is a pain in the arse. Any hot tips there? Why does Shopify mutate the ampersand in a bulk export?
It is simply escaping it to \u0026 in the JSONL (which is valid JSON encoding for the & character). Meanwhile, the GraphQL response is sending the raw ampersand back to you directly as &.
If you need to compare these two strings in your own app (or persist them in a consistent format), just decode the escaped characters in the JSONL string before comparing. Most programming languages have built-in ways of decoding escaped characters:
For example, in JavaScript, JSON.parse() on a properly escaped JSON string will convert \u0026 back to &.
In some languages, you might do a manual replace like str.replace(“\u0026”, “&”) if you’re handling raw text, but ideally you’d let a proper JSON parser handle it.
I was more or less pointing out how two identical GQL results return identical but not quite results. While it is true one can use built-in methods to ensure Apples are Apples, this exercise being inflicted is not zero-cost.
I accept that my subject matter at hand here is not requiring mountains be moved, but still, consistency in the platform is desirable above all else, not mental gymnastics and/or complexity.