Hello Sneha - 

I would implement that as a custom-code transformation (DTL).   That way it could be used in a router.   Would you consider posting it here?   I can show you how to convert it.   How are you storing the XML and the JSON?