Json object merge with unqiue id

Posted by Hitu on Stack Overflow See other posts from Stack Overflow or by Hitu
Published on 2014-08-20T09:47:37Z Indexed on 2014/08/20 10:20 UTC
Read the original article Hit count: 161

Filed under:
|

I have multiple json Objects

json1 = [
    {'category_id':1,'name':'test1' },
    {'category_id':1,'name':'test2' },
    {'category_id':1,'name':'test3' },
    {'category_id':2,'name':'test2' },
    {'category_id':3,'name':'test1' }
];

json2 = [{'category_id':1,'type':'test1'}];

json3 = [
    {'category_id':1,'color':'black'},
    {'category_id':2,'color':'black'},
    {'category_id':3,'color':'white'}
];

I am expecting output like this

final = [
    {'category_id':1,'name':'test1','type':'test`','color':'black' },
    {'category_id':1,'name':'test2','type':'test`','color':'black' },
    {'category_id':1,'name':'test3','type':'test`','color':'black' },
    {'category_id':2,'name':'test2','color':'black' },
    {'category_id':3,'name':'test1','color':'white' }
];

As i have long json object. Looping is good idea or not ? Does there is any inbuilt function for doing the same.

© Stack Overflow or respective owner

Related posts about JSON

Related posts about node.js