Hi Chanaka, Thanks. Using the above property inside a payload factory works fine.
Shazni Nazeer Mob : +94 777737331 LinkedIn : http://lk.linkedin.com/in/shazninazeer Blog : http://shazninazeer.blogspot.com On Tue, Mar 1, 2016 at 8:03 PM, Chanaka Fernando <chana...@wso2.com> wrote: > Hi Shazni, > > There should some information in the xml message to tell that it is an > array when there is only one element. Otherwise, JSON builder cannot figure > out it is an array. You can use the following in the xml message to > instruct the consumers about array. > > *<?xml-multiple?>* > > <users> > > <user>user1</user> > > </users> > > > > > > On Wed, Mar 2, 2016 at 12:35 AM, Shazni Nazir <sha...@wso2.com> wrote: > >> Hi, >> >> Say for example used a proxy below [1] to convert an xml to json. >> >> [1] >> >> <proxy xmlns="http://ws.apache.org/ns/synapse" name="XmlToJSON" >> transports="https,http" statistics="disable" trace="disable" >> startOnLoad="true"> >> <target> >> <inSequence> >> <property name="messageType" value="application/json" >> scope="axis2"/> >> <respond/> >> </inSequence> >> </target> >> <description/> >> </proxy> >> >> using a payload like [2] returns a response like [3] with a json array. >> >> [2] >> <users> >> <user>user1</user> >> <user>user2</user> >> </users> >> >> [3] >> >> { >> "users": { >> "user": [ >> "user1", >> "user2" >> ] >> } >> } >> >> using a payload like [4] returns a response like [5] without square >> brackets, since there's only one element. >> >> [4] >> <users> >> <user>user1</user> >> </users> >> >> [5] >> >> { >> "users": { >> "user": "user1" >> } >> } >> >> But I need to get this user1 in an array even if there's only one element in >> the array. I can however use a payload factory with a filter mediator like >> below to achieve this. Wondering if there's any other simple way to achieve >> without this? Your input is appreciated. >> >> [6] >> >> <filter source="json-eval($.StockQuotes.Stock.Symbol)" regex="null"> >> <then> >> <payloadFactory media-type="json"> >> <format>{ "StockQuotes": { "Stock": $1 } }</format> >> <args> >> <arg evaluator="json" expression="$.StockQuotes.Stock"/> >> </args> >> </payloadFactory> >> </then> >> <else> >> <payloadFactory media-type="json"> >> <format>{ "StockQuotes": { "Stock": [ $1 ] } }</format> >> <args> >> <arg evaluator="json" expression="$.StockQuotes.Stock"/> >> </args> >> </payloadFactory> >> </else> >> </filter> >> >> Shazni Nazeer >> Mob : +94 777737331 >> LinkedIn : http://lk.linkedin.com/in/shazninazeer >> Blog : http://shazninazeer.blogspot.com >> > > > > -- > Thank you and Best Regards, > Chanaka Fernando > Senior Technical Lead > WSO2, Inc.; http://wso2.com > lean.enterprise.middleware > > mobile: +94 773337238 > Blog : http://soatutorials.blogspot.com > LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0 > Twitter:https://twitter.com/chanakaudaya > > > > >
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev