简体   繁体   中英

Non-standard JSON and Azure Logic Apps

I have an API that produces JSON like this:

)]}',

{
    //JSON DATA
}

The //JSON DATA is valid JSON, but the )]}', up top is not.

When I try to GET this data via a Logic App, I get:

BadRequest. Http request failed: the content was not a valid JSON.

So, a few related questions:

1) Can I tell the logic app to return the invalid JSON anyway?

2) How can debug the issue better? I happen to know that the response is invalid, but what if I didn't? Can I see the raw data somewhere?

3) This is all done via the Azure web portal. Are there better tools? Visual Studio?

I should also mention that if I call a route on the same API that returns XML instead of JSON, then the Logic App works fine. So it definitely doesn't like the JSON response in particular.

Thanks!

First of all, please do not post three questions as a single question .


Question 1). The best thing you can do is make the API return a valid JSON object. This is good for million reasons. Here're a few:

  • it's pretty much a standard (either valid JSON or XML -- yeah, old school way);
  • therefore, no users of this API (including you) will need to struggle and guess what's going on and why;
  • your Logic App's step will just work without adding extra complexity;
  • you will make this world and your karma better.

If API-side changes are not within your reach, I don't think you can do much. If you're lucky and the HTTP action is successful (Status Code 2xx), you can try to use a Query Action with a function that truncates the first characters. It will look something like this (I don't know the exact syntax): @Substring(body('myHttpGet'), 4, length(body('myHttpGet')) - 4) where myHttpGet is the id of the Http Get action.

However, once again, if possible, I strongly recommend fixing up the API which is the root cause of the problem, instead of dealing with garbage response after that.

UPDATE Another thing you can do is wrap the dirty API. For example, you could create a trivial Azure Function that invokes the API you don't directly control, and sanitizes the response for you consumption requirements. This Azure Function function should be easy to call from the Logic App. It costs almost nothing (unless we're talking millions of requests/month). The only drawback here is the increasing latency, which may be not an issue at all -- test it and see whether it adds less than 100ms or so... Oh, and don't forget to file a ticket with the API owner, they make our world a bad place!


Question 2) In Azure Logic App web UI you can Look into the execution details and the error will definitely be there.

在此输入图像描述

在此输入图像描述

在此输入图像描述


Question 3) You're asking for a tool recommendation which is by definition a highly subjective thing and is off-topic on StackOverflow.

TL/DR: The other app is not producing valid JSON.

Meaning, this is not a problem for you to solve. The other app has to return valid JSON if the owner claims it should.

If they cannot or will not produce valid JSON, then the first thing you need to do is inform your management that you will have to spend a lot of extra time accommodating their non-standard format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM