Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
How to use JSON_INSERT with the key that is in string?

I'm not finding a way to use JSON_INSERT in a json whose key is a string:

{
 "computer": {
    "display": blue
  },
 "computer home":{}
}

This way it works:

JSON_INSERT(type, '$.computer.color', 'red');`

But not like this:

JSON_INSERT(type, '$.computer home.color', 'red');`

My wish:

{
 "computer" :{
    "display": "blue",
    "color": "red"

  },
 "computer home":{
   "color": "red"
 }
}

Apparently it's not working because the json key "computer home" has space, how can I insert it even with spaces?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Here's a demo:

mysql> set @j = '{
 "computer": {
    "display": "blue"
  },
 "computer home":{}
}';

(note I had to put "blue" in double-quotes too; all strings must be delimited that way in JSON)

You can use JSON keys that contain spaces (or punctuation too) by delimiting them with double-quotes:

mysql> select json_insert(@j, '$."computer home".color', 'red') as result;
+----------------------------------------------------------------------+
| result                                                               |
+----------------------------------------------------------------------+
| {"computer": {"display": "blue"}, "computer home": {"color": "red"}} |
+----------------------------------------------------------------------+
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda