[JSON Pretty Format] Tool Improvement

[JSON Pretty Format] Tool Improvement

  
Forge Component
(5)
Published on 12 Oct by Pedro Domingues
5 votes
Published on 12 Oct by Pedro Domingues

Hi guys,

First of all thank you for this tool. 

When using JSON Pretty Format, if you don't send correct JSON into it, it crashes.

I was using this web block more than 1 time in the same page, and (in this case) everytime 1 web block creashes, all bellow would crash too.

Improving your JavaScript, we were able to correct this problem, catching the error.

Script used:

"$(document).ready(function() {
  try {
    var obj = JSON.parse('"+ OriginalJSON + "')
    if (obj && typeof obj === 'object' && obj !== null) {
        var data = JSON.parse('" + 
        Replace(Replace(Replace(Replace(Replace(Replace(Replace(OriginalJSON,Chr(10),""),Chr(13),""),"'",""),"\n",""),"\r",""),"\""",""),"\t"," ")
    + "');
    $('#json-renderer" + JSONPrettyFormat.RuntimeId + "').jsonViewer(data,{collapsed: " + If(StartCollapsed,"true","false") + "});
    }
  } catch (err) {}
});"


Hope you enjoy it just like we did!

Best Regards,

DoItLean Support Team.

Tomás Dionísio wrote:

Hi guys,

First of all thank you for this tool. 

When using JSON Pretty Format, if you don't send correct JSON into it, it crashes.

I was using this web block more than 1 time in the same page, and (in this case) everytime 1 web block creashes, all bellow would crash too.

Improving your JavaScript, we were able to correct this problem, catching the error.

Script used:

"$(document).ready(function() {
  try {
    var obj = JSON.parse('"+ OriginalJSON + "')
    if (obj && typeof obj === 'object' && obj !== null) {
        var data = JSON.parse('" + 
        Replace(Replace(Replace(Replace(Replace(Replace(Replace(OriginalJSON,Chr(10),""),Chr(13),""),"'",""),"\n",""),"\r",""),"\""",""),"\t"," ")
    + "');
    $('#json-renderer" + JSONPrettyFormat.RuntimeId + "').jsonViewer(data,{collapsed: " + If(StartCollapsed,"true","false") + "});
    }
  } catch (err) {}
});"


Hope you enjoy it just like we did!

Best Regards,

DoItLean Support Team.

Tomás, thanks for sharing! Hope the team implement this soon in a next version.


Hi Guys,

Thanks a lot for your great improvement.

I have just uploaded a new version with the fix.

Have a great weekend.

Cheers,