What I have and what I know:
- json array like {"home":["1","2","5"], "work":["15","16","19"]}
- new integer element ("11" for example)
- place for new element "home" or "work" ("home" for example)
What I need:
- Add this element to end of json array in right place
- Do it with reqular expression
- Do it in postgreSQL with regexp_replace
- Result must be like this: {"home":["1","2","5","11"], "work":["15","16","19"]}
What I was try:
SELECT regexp_replace('{"home":["1","2","5"], "work":["15","16","19"]}', '(.*)("home":\[)(("[0-9]*",)*("[0-9]*")*)(\])(.*)', '\1\2\3,"11"\6\7', 'g');
What I don't know: - What if place will be "home":[] and I must put "11" without ","! how?