Hi, Try using PayloadFactory mediator as below. Change your configs as following.
*modifyAgRes.xml* <case regex="2"> <payloadFactory media-type="xml"> <format> <jsonObject xmlns=""> <id>$1</id> <children xmlns=""> <id>$1</id> <make>$2</make> <name>Car</name> <model>Tmaze</model> </children> </jsonObject> </format> <args> <arg evaluator="xml" expression="//jsonObject/id"/> <arg evaluator="xml" expression="//jsonObject/make"/> </args> </payloadFactory> </case> <case regex="3"> <payloadFactory media-type="xml"> <format> <jsonObject xmlns=""> <id>$1</id> <children xmlns=""> <id>$1</id> <make>$2</make> <name>Mobile</name> <model>S8</model> </children> </jsonObject> </format> <args> <arg evaluator="xml" expression="//jsonObject/id"/> <arg evaluator="xml" expression="//jsonObject/make"/> </args> </payloadFactory> </case> ---------------------------------------------------------- <!--enrich> <source clone="true" xpath="//jsonObject"/> <target type="body"/> </enrich--> *addChild.xml*<property name="aggrementResponse" expression="//jsonObject/children" scope="default" type="OM"/> <enrich> <source xpath="get-property('aggrementResponse')"/> <target action="sibling" xpath="get-property('firstResponse')/children"/> </enrich> Thanks Sudharma On Thu, Jul 20, 2017 at 2:03 AM, aditya shivankar < shivankar.adit...@gmail.com> wrote: > Adding responses as elements ,to an array in json response > > Input request : > > [ > { > "id" : "1", > "make" : "TAHB", > "children":[ > { > "kid":"1" > }, > { > "kid":"2" > } > ] > }, > { > "id" : "2", > "make" : "Tonda" > }, > { > "id" : "3", > "make" : "Tamsung" > } > ] > > > I am using iterate, to send each element of above array as request to a > backend service( In myactual project this is not so simple service i.e. > backend service reponse is very complex json with lots of arrays and > sub-arrays(child arrays)in it . for better understanding of issue I kept it > like this ). > > The responses of the backend service are aggregated in one soap xml by > AggregateMediator. > > Below is response from AggregateMediator > > <?xml version='1.0' encoding='utf-8'?> > <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ > "> > <soapenv:Body> > <Information> > <jsonObject> > <id>1</id> > <make>TAHB</make> > <children> > <kid>1</kid> > </children> > <children> > <kid>2</kid> > </children> > <name>Home</name> > <area>5000sqft</area> > </jsonObject> > <jsonObject> > <id>2</id> > <make>Tonda</make> > <name>Car</name> > <model>Tmaze</model> > </jsonObject> > <jsonObject> > <id>3</id> > <make>Tamsung</make> > <name>Mobile</name> > <model>S8</model> > </jsonObject> > </Information> > </soapenv:Body> > </soapenv:Envelope> > > Requirement is to add all the responses from the backend service except > the first one, to the child array of the first response of the backend > service. > I do not know how to do this ? not even how to add new elements to a array > in wso2. > > My Current Output : > > { > "id": 1, > "make": "TAHB", > "children": [{ > "kid": 1 > }, > { > "kid": 2 > }], > "name": "Home", > "area": "5000sqft", > "jsonObject": [{ > "id": 2, > "make": "Tonda", > "name": "Car", > "model": "Tmaze" > }, > { > "id": 3, > "make": "Tamsung", > "name": "Mobile", > "model": "S8" > }] > } > > > Desired Output : > > { > "id": 1, > "make": "TAHB", > "children": [ > { > "kid": 1 > }, > { > "kid": 2 > }, > { > "id": 2, > "make": "Tonda", > "name": "Car", > "model": "Tmaze" > }, > { > "id": 3, > "make": "Tamsung", > "name": "Mobile", > "model": "S8" > } > ], > "name": "Home", > "area": "5000sqft", > } > > Please find main xml and backendService xml attached. It contains what I > tried. > main xml : addChild.xml > backendService xml : modifyAgrRes.xml > > > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- Sudharma Subasinghe, Software Engineer, WSO2 Inc. Email: sudhar...@wso2.com <hasi...@wso2.com> Mobile : +94 710 565 157 <%2B94%20718%20210%20200>
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev