Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!