Curl Ggraphql return special character

Curl Ggraphql return special character

CStefano
Excursionist
14 3 0

hi, I don't understand why from shopify-graphiql-app the result is in html code

 

{ "key": "body_html", "value": "\nLa Chemise pour Homme Leonardo Essential avec col boutonné en coton Oxford bleu clair est une véritable incarnation du style classique, de l'élégance intemporelle et de l'artisanat italien.\n\n<ul>\n\t<li><strong>Élégance Classique</strong> : Rehaussez votre garde-robe avec cette pièce essentielle qui incarne sans effort l'élégance classique. Le col boutonné ajoute une touche de sophistication, en faisant un choix polyvalent pour toute occasion.</li>\n\t<li><strong>

 

 

but if I do a request from curl the result is different

 

 

[{"key":"body_html","value":"\nLa Chemise pour Homme Leonardo Essential avec col boutonné en coton Oxford bleu clair est une véritable incarnation du style classique, de l'élégance intemporelle et de l'artisanat italien.\n\n\u003cul\u003e\n\t\u003cli\u003e\u003cstrong\u003eÉlégance Classique\u003c\/strong\u003e : Rehaussez votre garde-robe avec cette pièce essentielle qui incarne sans effort l'élégance classique. Le col boutonné ajoute une touche de sophistication, en faisant un choix polyvalent pour toute occasion.\u003c\/li\u003e\n\t\u003cli\u003e\u003cstrong\u003eAttrait Intemporel\u003c\/strong\u003e : La Chemise Leonardo Essential est un témoignage du style intemporel, vous assurant de dégager une aura de raffinement qui ne 

 

 

I need html code <ul> not \u003cul\u003e

is a curl problem? is parameter?

Replies 2 (2)

Liam
Community Manager
3108 340 871

Hi CStefano,

 

When you query from the Shopify GraphiQL App, the app is decoding the Unicode escape sequences for display, making it more human-readable. However, when you fetch the data using curl, you're getting the raw JSON response, which includes the Unicode escape sequences.

 

To get the desired HTML format from the curl response, you'll need to decode the Unicode escape sequences. Here's how you can handle this:

 

1. Using a Tool or Library:
Many programming languages have libraries or built-in functions to decode Unicode escape sequences in strings. For example, in Python you could do the following:

 

 

import json

raw_data = '[{"key":"body_html","value":"..."}]' # Your raw JSON data here
decoded_data = json.loads(raw_data)
print(decoded_data[0]['value'])

 


2. Using jq with curl:
If you're using curl in the command line, you can pipe the output to jq to parse and decode the JSON:

curl YOUR_URL_HERE | jq -r '.[0].value'

The -r flag in jq tells it to output raw strings, decoding any escape sequences.

 

3. Check Headers and Parameters:
Ensure that you're setting the Accept header to application/json when making the curl request. This ensures that the server knows you want a JSON response.

curl -H "Accept: application/json" YOUR_URL_HERE

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

CStefano
Excursionist
14 3 0

Hi thank you for the reply..

the problem is that I receive the data from CURL

 

curl -X POST -H "Accept: application/json" "https://mysite.myshopify.com/admin/api/2022-04/graphql.json" -H "Content-Type: application/json" -H "X-Shopify-Access-Token: mykey" -d "{\"query\": \"query { translatableResource(resourceId: \\\"gid://shopify/Product/8305135026440\\\") { resourceId translations(locale: \\\"fr\\\") { key value}}}\"}"

 

and I put the result into a table...