I have column content in my database that is a type of STRING with JSON structure:
{
"id": "12",
"Name": "Ana",
"lastName": "Johnes",
"data": [{
"id": "2",
"value": "mr"
}, {
"id": "3",
"value": "Ana"
}
]
}
Schema of myTable:
Content (STRING)
I want to hash and update the 'value' inside the data. I tried using REPLACE function like this but it didn't replace the array "data" with hashed "value":
UPDATE `myTable` set content=
REPLACE(content, ARRAY_TO_STRING(ARRAY(
SELECT
data
FROM
UNNEST(json_extract_array(content,
"$.data"))AS data), ","),ARRAY_TO_STRING(ARRAY(
SELECT
REPLACE(data, "\""||json_value(data,
"$.value")|| "\"", '"'||`hashField`(json_extract_scalar(data,
'$.value'))||'"' )
FROM
UNNEST(json_extract_array(content,
"$.data")) AS data), ","))
WHERE true
Expected output in column content should look like this:
{
"id": "12",
"Name": "Ana",
"lastName": "Johnes",
"data": [{
"id": "2",
"value": "1256f52fe6125"
}, {
"id": "3",
"value": "6712gf7e1fe76"
}
]
}


{ "id": "12", "Name": "Ana", "lastName": "Johnes", "data": [{ "id": "2", "value": "25623g7263d672gd" }, { "id": "3", "value": "67fwevtwe76d7t", } ] }