Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

Tuesday, December 9, 2014

How to delete the element in the array of json object in Java-script

Recently we had a very basic requirement to delete an key value pare in the json array using Javascript.


Input data

{"invideoPromotion":{"items":[{"id":{"type":"video","videoId":"11","websiteUrl":""},"timing":{"type":"ms","offsetMs":"2222"},"customMessage":"aa","promotedByContentOwner":"vanji"}]}}

Expected business logic

When type of id is video and websiteUrl is null; websiteUrl should be removed from the payload.

Output data

{"items":[{"id":{"type":"video","videoId":"11"},"timing":{"type":"ms","offsetMs":"2222"},"customMessage":"aa","promotedByContentOwner":"vanji"}]}}

In-order to do this you can use delete functionality of the json in javascript.

Example code



Monday, July 29, 2013

JSON to XML conversion using WSO2 ESB

I am using WSO2 ESB 4.6.0 version to demonstrate this sample, simple yet powerful.

You do not need to write your own code or relay on other library to convert json to xml. Simple WSO2 esb proxy can do the conversion for you, so we will try that. 

Lets set the requirement is to use a parameter to the methods to control whether to return JSON or XML. 

Given synapse configuration below has the very basic configuration to solve this requirement.


"JsonToXmlApi" rest api has two resource in the "Test" context. "/xml/" resource will covert the incoming json payload into xml format and send that back to client. whereas,  "/json/" resource without converting which will echo back to the client.

You can test this using curl commands that have given below,