Posted: Tue Nov 17, 2015 9:59 am Post subject: parsed blob data needs to be assesed if its JSON or XML
Apprentice
Joined: 20 Aug 2013 Posts: 26
I have a flow in which we are invoking a restful service using HTTPRequest node and that request hits the datapower and gives back the response and the response from datapower is expected to be JSON. We are getting back JSON response in most of ideal cases except 1 scenario i.e. when the datapower timesout while processing the request and returns back XML as response and it fails in the HTTPRequest node. Ideally the datapower has to return JSON but due to some constraint the changes in DP is in prgress but mean while we are thinking to change the PARSER in the httprequest node to BLOB and then we would write a function to check if the BLOB is really a XML or JSON and reparse it accordingly. Is there a way to check if the BLOB is XML or JSON before its parsed by RCD node?
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
Look at the first character and see if is a <
You can cast the < as a blob and then extract the same length from the input BLOB.
IF they match then you have XML otherwise assume it is JSON.
There are probably other ways. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
If it works once then it will probably work every time. But it only works when the document does not start with a Byte Order Mark.
mqjeff's suggestion will always work.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum