I'm trying to update the data stored in a json column in MariaDB (libmysql version - 5.6.43 , Server: 10.3.34-MariaDB-cll-lve - MariaDB Server).
My data is structured like this:
| ID | json_data | 
|---|---|
| 1 | {....} | 
| 2 | {....} | 
where json_data is structured as follows:
{
    "company": {
        "id": "",
        "name": "",
        "address": ""
    },
    "info_company": {
          "diff_v": "1",
          "grav_v": "",
          "diff_s": "2",
          "grav_s": "",
          "diff_g": "3",
          "grav_g": "",
          "diff_ri": "4",
          "grav_ri": "2"
    }
}
I'm trying to update data inside info_company replacing:
- "1" with "<50%"
- "2" with "<50%"
- "3" with ">50%"
- "4" with ">50%"
so the result should be:
{
    "company": {
        "id": "",
        "name": "",
        "address": ""
    },
    "info_company": {
          "diff_v": "<50%",
          "grav_v": "",
          "diff_s": "<50%",
          "grav_s": "",
          "diff_g": ">50%",
          "grav_g": "",
          "diff_ri": ">50%",
          "grav_ri": "<50%"
    }
}
By writing this query, I can retrieve the info_company data, but then for each key contained I cannot update the data following the new value.
SELECT new_t.id, JSON_EXTRACT(new_t.json_data, “$.info_company“) FROM (SELECT * FROM `my_table` WHERE json_data LIKE “%info_company%”) new_t
Output:
| ID | json_data | 
|---|---|
| 1 | {"diff_v": "1","grav_v": "","diff_s": "2","grav_s": "","diff_g": "3","grav_g": "","diff_ri": "4","grav_ri": "2"} | 
Thank you for your help.
 
     
     
    