1

My object is

{
"name":"Testing",
"id": "hcig_3fe7cb00-e936-11e6-af69-a748c8cc89ad",
"belongsTo": {
    "id": "69616d26-c3bb-405c-8c84-c51c091524b2",
    "name": "test"
},
"locatedAt": {
    "id": "49616d26-c3bb-405c-8c84-c51c091524b2",
    "name":"Test"
}  }

I want to merge one more object like

"obj":[{
    "a": 123
 }}

With the help of JSON_MERGE in mysql document store i am able to add object. But it looks likes

{
"name":"Tester",
"id": "hcig_3fe7cb00-e936-11e6-af69-a748c8cc89ad",
"belongsTo": {
    "id": "69616d26-c3bb-405c-8c84-c51c091524b2",
    "name": "test"
},
"locatedAt": {
    "id": "49616d26-c3bb-405c-8c84-c51c091524b2",
    "name":"Test"
},{
    "obj":[{
    "a": 123
 }]
}}

I want my object to be as

{
  "name": "Tester",
  "id": "hcig_3fe7cb00-e936-11e6-af69-a748c8cc89ad",
  "belongsTo": {
     "id": "69616d26-c3bb-405c-8c84-c51c091524b2",
     "name": "test"
  },
 "locatedAt": {
   "id": "49616d26-c3bb-405c-8c84-c51c091524b2",
   "name": "Test"
 },
 "obj": [{
    "a": 123
}]}

Any idea on how to add object as above manner using JSON Functions in mysql ??

2
  • You may try this stackoverflow.com/questions/17099089/… Commented Feb 7, 2017 at 6:41
  • @kawadhiya21 :- Yes that is working, but i have syntax like :- UPDATE device SET doc = CONCAT_WS(",", SUBSTRING(doc, 1, CHAR_LENGTH(doc) - 1),SUBSTRING('{"a":"{"b":"123"}"}', 2)) where id = '6aa02850-ed01-11e6-af3b-9d6a036cc416'; For this it is not working . Commented Feb 7, 2017 at 6:59

1 Answer 1

0

Use lodash for a recursive deep copy - https://lodash.com/

lodash.merge(targetObj, sourceObj);

Or if you have programmatic access:

targetObj.obj = sourceObj;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.