Forum Discussion

kumar25's avatar
kumar25
New Contributor II
3 years ago

How to pass HTTP codes in JSON output

Hi,

I have a JSON like below, have to pass the value of StatusCode into HTTP Header. I am using JSON Formatter, but incase of Failure also it gives 200 with the actual code in the JSON payload. Help me in how to handle this

JSON:
{
“StatusCode”:“500”,
“StatusMessage”:“Success”
}

4 Replies

  • Hi @kumar25,

    You can add the headers you want in the Binary header properties in the JSON Formatter snap.
    In your case instead of using ‘500’ in the expression field like in the sample below, you can use $StatusCode.

  • kumar25's avatar
    kumar25
    New Contributor II

    Hi @j.angelevski ,

    I am able to get the error code in HTTP header along with that the entire message is published in the payload(as i am passing the entire input in the content of JSON Formatter).

    How can i exclude statuscode field to be populated in the response.

    • j_angelevski's avatar
      j_angelevski
      Contributor III

      @kumar25

      You can choose what to provide in the response by changing the Content property by selecting the
      StatusMessage field from the input or you can have a Mapper snap before the JSON Formatter and map the values that you only need.