Do forward slashes really have to be escaped in JSON input?

When I look at GraphQL API responses or the input (STDIN) provided in my function logs, I can see that forward slashes (/) are passed and displayed correctly:

However, when I begin parsing the actual STDIN payload in my Rust-based function, I encounter unnecessarily escaped forward slashes in the text:

{
"id":"gid:\/\/shopify\/ProductVariant\/44519810826520",
"sku":"28800",
"title":"BLACK \/ MEDIUM" 
...
}

This seems suboptimal for several reasons:

  • It unnecessarily increases the size of the JSON payload, making it more likely to hit the InputSizeLimitExceededError on large shopping carts.
  • It slightly slows down input parsing.
  • It requires extra buffering or allocations (rather than simple substring referencing) to store unescaped field values like "title" in the example above.

So, I wanted to ask: is this something that could be adjusted on Shopify’s side? The JSON standard does not require escaping forward slashes, so including these extra backslashes appears to be unnecessary.

Hey @eugals :waving_hand: - thanks for flagging this. Looking into this on my end, I’ll loop back with you when I have more info to share.

Hi @eugals I believe what you’re experiencing is an artifact of our JSON encoding. In the recent Summer Editions, we actually released the Wasm API, which should address this encoding issue in addition to providing some other benefits!

To take advantage of this, you just need to update your CLI and shopify_function Rust package. See this page for more information.

Thanks @Liam-Shopify!

I wouldn’t call this an issue though. Just a little suboptimal implementation of process responsible for forwarding the payloads to my WASM.
The payload itself was handled all right by the previous shopify_function’s version as well.

Sorry for the confusion.

1 Like