โ07-21-2022 12:49 AM
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:-
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
โ07-22-2022 02:59 AM
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.