Hi Naasheer,
You can do this via Script mediator to delete the object that you do not
need.
This java script is simple example[1] that i can point out you for your
requirement.
*Input *
{"invideoPromotion":{"items":[{"id":{"type":"video","videoId":"11","websiteUrl":""},"timing":{"type":"ms","offsetMs":"2222"},"customMessage":"aa","promotedByContentOwner":"vanji"}]}}
*Expected Business logic to be performed*
When id type is video and websiteurl is null, websiteurl need to be get
delete.
*Expected output*
{"items":[{"id":{"type":"video","videoId":"11"},"timing":{"type":"ms","offsetMs":"2222"},"customMessage":"aa","promotedByContentOwner":"vanji"}]}}
[1]
var text =
'{"invideoPromotion":{"items":[{"id":{"type":"video","videoId":"11","websiteUrl":""},"timing":{"type":"ms","offsetMs":"2222"},"customMessage":"aa","promotedByContentOwner":"vanji"}]}}'
var obj = JSON.parse(text);
document.writeln(JSON.stringify(obj));
for (var i = 0; i < obj.invideoPromotion.items.length; i++) {
if (obj.invideoPromotion.items[i].id.type == 'video') {
if (obj.invideoPromotion.items[i].id.websiteUrl == '') {
delete obj.invideoPromotion.items[i].id.websiteUrl;
}
}
}
document.writeln(JSON.stringify(obj));
On Tue, Dec 9, 2014 at 3:04 PM, Irham Iqbal <[email protected]> wrote:
> Hi Naasheer Ali,
>
> How you're creating this json ?
>
> If you're creating this json from a POJO class, I think you can't delete
> the field as you want. Because you have define those variables inside the
> POJO.
>
> Thanks,
> Iqbal
>
>
> On Tue, Dec 9, 2014 at 10:43 AM, Naasheer Ali <[email protected]> wrote:
>
>> Hi All,
>> I'm doing YouTube connector for ESB. Below I've written a JSON
>> payload to send a request to ESB, Most of them are optional parameters. I
>> need to selectively delete a parameter from the payload when the value of
>> the parameter is not assigned to it.
>> Say, If I didn't give any value to brandingSettings.channel.description,
>> description should be deleted from the payload and others should be there
>> as it is and I wanna delete a parameter from the array say,
>> brandingSettings.image.backgroundImageUrl.localized.language, How can I
>> delete it?.
>>
>>
>> {
>> "id":" ",
>> "brandingSettings":
>> {
>> "channel":
>> {
>> "description":" ",
>> "keywords":" ",
>> "defaultTab":" ",
>> "trackingAnalyticsAccountId":" ",
>> "moderateComments":" ",
>> "profileColor":" ",
>> "showRelatedChannels":" ",
>> "showBrowseView":" ",
>> "featuredChannelsTitle":" ",
>> "featuredChannelsUrls":" ",
>> "unsubscribedTrailer":" "
>> },
>> "image":
>> {
>> "backgroundImageUrl":
>> {
>> "default":" ",
>> "localized":
>> [
>> {
>> "language":" ",
>> "value":" "
>> }
>> ]
>> },
>> "bannerExternalUrl":" "
>> }
>> },
>> "invideoPromotion":
>> {
>> "position":
>> {
>> "cornerPosition":" ",
>> "type":" "
>> },
>> "defaultTiming":
>> {
>> "type":" ",
>> "offsetMs":" "
>> },
>> "items":
>> [
>> {
>> "id":
>> {
>> "type":" ",
>> "videoId":" ",
>> "websiteUrl":" "
>> },
>> "timing":
>> {
>> "type":" ",
>> "offsetMs":" "
>> },
>> "customMessage":" ",
>> "promotedByContentOwner":" "
>> }
>> ]
>> }
>> }
>>
>> Regards,
>> --
>>
>> *Naasheer Ali* | Associate Software Engineer
>>
>> WSO2, Inc |#20, Palm Grove, Colombo 03, Sri Lanka
>>
>> Email: [email protected]
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Irham Iqbal
> Software Engineer - Test Automation
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
> phone: +94 777888452
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
--
Sivajothy Vanjikumaran
*Senior Software Engineer*
*Integration Technologies Team*
*WSO2 Inc. http://wso2.com <http://wso2.com/>*
*Mobile:(+94)777219209*
[image: Facebook] <https://www.facebook.com/vanjikumaran> [image: Twitter]
<https://twitter.com/vanjikumaran> [image: LinkedIn]
<http://www.linkedin.com/pub/vanjikumaran-sivajothy/25/b31/293> [image:
Blogger] <http://vanjikumaran.blogspot.com/> [image: SlideShare]
<http://www.slideshare.net/vanjikumaran>
This communication may contain privileged or other confidential information
and is intended exclusively for the addressee/s. If you are not the
intended recipient/s, or believe that you may have received this
communication in error, please reply to the sender indicating that fact and
delete the copy you received and in addition, you should not print,
copy, re-transmit, disseminate, or otherwise use the information contained
in this communication. Internet communications cannot be guaranteed to be
timely, secure, error or virus-free. The sender does not accept liability
for any errors or omissions
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev