167
Views
2
Comments
[JSON Pretty Format] Tool Improvement
Question
json-pretty-format
Web icon
Forge asset 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.

Capture.JPG
2017-10-09 20-45-22
André Siébra

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.


2026-03-23 09-58-51
Pedro Domingues
Champion

Hi Guys,

Thanks a lot for your great improvement.

I have just uploaded a new version with the fix.

Have a great weekend.

Cheers,

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.