I have a simple database that stores fields and values in a JSON column to create custom forms using PHP { "Field1": "Value1", "Field2": "Value2" }.
Compulsory fields are sored with an asterisk *: { "Field3*": "Value3" }.
The problem comes when I try to update the compulsory field, I think that's because of escaping issues.
When I try to update the script I should use isn't clear to me.
UPDATE Forms SET Form=JSON_SET('Form','$.Field3*','Value3') WHERE Some=attributes;UPDATE Forms SET Form=JSON_SET('Form','$.Field3\*','Value3') WHERE Some=attributes;(with one backslah)UPDATE Forms SET Form= JSON_SET ('Form','$.Field3\\*', 'Value3') WHERE Some=attributes;(with two backslahes)UPDATE Forms SET Form=JSON_SET('Form','$.Field3\\\*','Value3') WHERE Some=attributes;(with three backslahes)
I tried all of these but:
- when a new Form is created the first works,
- when a form is updated and the field
Field3*already exists the fourth works, - when a Form is updated but the field
Field3*doesn't exists the fourth creates a field calledField\*that messes everything up.
https://dev.mysql.com/doc/refman/8.0/en/json.html#json-path-syntax
This means if your keys contain special characters (such as spaces, digits, punctuation, etc.) that make them not valid ECMAScript identifiers, then you must put the keys in double-quotes in a JSON Path.
Demo: