Issues editing a json field using the json editor

Hi! I'm having some issues when trying to edit a json formated field in one table in my db using the json editor component.

The value in my db looks like this (screenshot2):

{
    "channels": [
        {
           "name": "Llevar",
            "channel": "pickup",
            "icon_url": "https://img.oky.app/master_img/iconos_pickup.webp"
        },
        {
            "name": "Mesas",
            "channel": "tables",
            "icon_url": "https://img.oky.app/master_img/iconos_mesas.webp"
        }       
    ],    
    "people": {
        "title": "Alcanza para",
        "value": "5"
    }
}

However when I use the json editor component and reference that table value it comes back like this (screenshot1):

"{\r\n    \"channels\": [\r\n        {\r\n           \"name\": \"Llevar\",\r\n            \"channel\": \"pickup\",\r\n            \"icon_url\": \"https://img.oky.app/master_img/iconos_pickup.webp\"\r\n        },\r\n        {\r\n            \"name\": \"Mesas\",\r\n            \"channel\": \"tables\",\r\n            \"icon_url\": \"https://img.oky.app/master_img/iconos_mesas.webp\"\r\n        }       \r\n    ]\r\n}"

Which looks messy and not that friendly. A dev will be able to understand it and edit it but the app I'm building is for a different not so techy team.

If I try to paste the first code format on the json editor and try to save it I get an error message "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''[object Object]', '[object Object]', people = '[object Object]' WHERE id_...' at line 2"

To update I'm just using a standard UPDATE sql:

UPDATE cat_esp_giftcard
SET metadata = {{ jsonEditor1.value }}
WHERE id_giftcard = {{ tablaVales.selectedRow.id_giftcard }}

Is there a way to make the json editor more fiendly or if I'm doing something wrong I would also highly appreciate your input. Thanks!

Screenshot 2023-09-06 112139
Screenshot 2023-09-06 112254

hello what is your field type of metadata in your database, string or jsonb

you can use JSON.parse() to prase string from table to json , as use it as value of json editor

2 Likes

Many thanks Anson! Saw this but forgot to reply.