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.