How can I update a customer metafield of type JSON?

Hello.

I would like to update a customer metafield of type JSON from the storefront for logged in shop users. I have tried it via the graphql API with mutations, but I keep getting an error that I can’t understand. My code with javascript looks like this at the moment. If it works I would want to do the whole thing with php on the server side afterwards.

const customer_id = ‘xyzxyzxyz’;

const jsonData = [
{
“key1”: “value1”,
“key2”: “value2”
},
{
“key1”: “value1”,
“key2”: “value2”
}
];

const updateMetafieldMutation = mutation { customerUpdate(input: { id: "gid://shopify/Customer/${customer_id}", metafields: { key: "customer.metafields.custom.myfieldkey" }, value: "${JSON.stringify(jsonData)}", namespace: "global" } }) { customer { id } } };

fetch(‘https://mydomain.myshopify.com/api/2024-04/graphql.json’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
‘X-Shopify-Storefront-Access-Token’: ‘myaccesstoken’,
},
body: JSON.stringify({ query: updateMetafieldMutation }),
})
.then(response => response.json())
.then(data => {
console.log(‘Metafield updated successfully:’, data);
})
.catch(error => {
console.error(‘Error updating metafield:’, error);
});

This is the error I get, do you have any idea what the problem could be and whether my approach to doing it this way is correct?

“Parse error on “:” (STRING) at [6, 36]”

Thank you very much.