Hi Aditya,

Could you please try out following approach?


First use  enrich mediator create a root element. Next inside iterate
mediator (where you iterate your payload) add a payload mediator to create
a json object  and pass the property values. Then you can add it as a child
element to the initially created root element with enrich mediator.
Following is a sample flow which explains the idea.

            <enrich>
            <source clone="true" type="inline">
               <jsonArray/>
            </source>
            <target property="RootElm" type="property"/>
         </enrich>

         <iterate...>
         <target>
         <sequence>
<payloadFactory media-type="json">
            <format>

{
"name":"$1",
"price":"$2"
}
            </format>
            <args/>
         </payloadFactory>

         <enrich>
            <source clone="true" type="body"/>
            <target action="child" xpath="$ctx:RootElm"/>
         </enrich>

         <property name="messageType" scope="axis2"
value="application/json"/>
         <property name="contentType" scope="axis2"
value="application/json"/>
         </sequence>
         </target>
         </iterate>

Thanks,
Himasha

On Tue, Jan 23, 2018 at 4:24 PM, aditya shivankar <
[email protected]> wrote:

> Respected sir,
> I have a response big json response from one backend service.
> Suppose the response is in my payload.
> I am running the loop on Children element of this payload.
>
> I want to extract two values in each loop, say name and price and keep it
> in an property. Say like below
>
> [{
> "name":"mobile",
> "price":"1000"
> }]
>
> I am not able to create a array inside property like this.
>
>  then in the second loop , when I extaxct two new values for name(say
> "bottle") and price(say "50"). I want to add them to my property as follows
> [
> {
> "name":"mobile",
> "price":"1000"
> },
> {
> "name":"bottle",
> "price":"50"
> }
>
> ]
>
> I am not add this new element to the existing array.
>
> Please guide.
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Himasha Guruge
Senior Software Engineer
WS*O2* *Inc.*
Mobile: +94 777459299
[email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to