cancel
Showing results for 
Search instead for 
Did you mean: 

Possible to format JSON in Logger or Email?

gsbrown
Deputy Chef I
Deputy Chef I

I have a recipe with an HTTP Request action with monitor error handling to logger and email.   I can attach the HTTP Response "Body" field into the logger and email,  but is there a way to apply JSON formatting to it so it's easier to read? 

2 ACCEPTED SOLUTIONS

gary1
Executive Chef III
Executive Chef III

You can do this with a quick JavaScript action.

Create one with an input and output like this. Replace the message data pill with your HTTP response:

gary1_1-1701726931127.png

Use this code:

exports.main = async ({ obj }) => {
  var pretty = JSON.stringify(obj, null, "\t");
  return { pretty };
}

 

You can use the "pretty" output pill as-is in a plaintext email to get this:

gary1_3-1701727076625.png

If you want to use it in an HTML email, use "pre" like this:

gary1_4-1701727111306.png

Emails like this in monospace font:

gary1_5-1701727133072.png

Hope this helps!

View solution in original post

gsbrown
Deputy Chef I
Deputy Chef I

It's working now,  thank you!

Realized,  from the "Send Request via HTTP" action I needed to pass through the "Response" datapill and not the "Body" containing the "Response"

View solution in original post

4 REPLIES 4

gary1
Executive Chef III
Executive Chef III

You can do this with a quick JavaScript action.

Create one with an input and output like this. Replace the message data pill with your HTTP response:

gary1_1-1701726931127.png

Use this code:

exports.main = async ({ obj }) => {
  var pretty = JSON.stringify(obj, null, "\t");
  return { pretty };
}

 

You can use the "pretty" output pill as-is in a plaintext email to get this:

gary1_3-1701727076625.png

If you want to use it in an HTML email, use "pre" like this:

gary1_4-1701727111306.png

Emails like this in monospace font:

gary1_5-1701727133072.png

Hope this helps!

gary1
Executive Chef III
Executive Chef III

I see some encoding problems in the input (it's passing as a string instead of an object).

Is the input field set to formula mode or text mode? Make sure it's formula. This might fix it.

gary1_0-1701731167417.png

 

gsbrown
Deputy Chef I
Deputy Chef I

It's working now,  thank you!

Realized,  from the "Send Request via HTTP" action I needed to pass through the "Response" datapill and not the "Body" containing the "Response"

gary1
Executive Chef III
Executive Chef III

Excellent, that would have been my follow up suggestion! The "body" is encoded as a string, but the parsed response gets passed as an object.