cancel
Showing results for 
Search instead for 
Did you mean: 

How can we "prettify" a Json data section presented in an email with the HTML table template type chosen?

MikeP
New Contributor II

Hello community, is there anyway we can manipulate a part of a document for a json section to make it more reader friendly ie prettify it, especially in the html table format option in the Email sender snap. So it doesn’t look bunched in the email body, in a table column and much more reader friendly. This is a small example of the problem:-

image

So its maybe looks like this in the email body when its rendered :-

{
“Results”:{
“Title”:" Results 2",
“FileInfo”:{
“Files”:[
{
“Name”:“OLD”,
“Type”:“Directory”
}
]
}
},
“Files”:[
{
“Name”:“OLD”,
“Type”:“Directory”
}
]
}

Ok so the editor had screwed the tabbing structure up here, but you get the idea!

Any help appreciated.

Many thanks,
Mike

1 REPLY 1

bojanvelevski
Valued Contributor

Hey @MikeP ,

Somewhere in the process the JSON is improperly stringified. Proper way of doing this (in snaplogic) would be:

JSON.stringify($jsonObject)

Here’s an expression that I believe would help in most of the cases:

JSON.parse($jsonObject.replaceAll('{','{"').replaceAll('}','"}').replaceAll('=','":"'))

I’m saying in most of the cases because keys or values can contain some of the characters I’m replacing in the expression. The purpose of replacing is to be able to parse the JSON again, and if some of the characters are present in key/value, than those will be replaced with the character set accordingly and the JSON will be kind of transformed.