Click here to Skip to main content
15,443,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have below two objects which I want to merge.

[
    {
        "response_code": 1,
        "response_message": [
            {
                "a": 1000,
                "b": 1000001,
                "c": 10000002
            }
        ]
    },
    {
        "response_code": 1,
        "response_message": [
		"p": 1000,
                "q": 1000001,
                "r": 10000002
	]

    }
]


I want to merge them like below by having only one value of response code and merge values of response message like below way.

{
    "response_code": 1,
    "response_message": [
        {
                "a": 1000,
                "b": 1000001,
                "c": 10000002
            },
        {
            "p": 1000,
                "q": 1000001,
                "r": 10000002
        }
    ]
}


I am not able to do it.

What I have tried:

Really stuck with such complicated merging where I want only once the value of response code and merge the values of response message.
Posted
Updated 16-Mar-20 7:10am
Comments
Gerry Schmitz 16-Mar-20 10:53am    
It's not a "merge"; it's an "grouping". As shown, you create a "group", keying (apparently)) on response_code.
Telstra 16-Mar-20 11:10am    
do you have any sample code to do so. I am trying from https://stackoverflow.com/questions/14446511/most-efficient-method-to-groupby-on-an-array-of-objects here but no luck.
Maciej Los 16-Mar-20 13:05pm    
Use "Reply" widget to be sure that system will inform user about your response.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900