Announcement

Collapse
No announcement yet.

Need Help JSON Formating?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Help JSON Formating?

    Hi IRF users, i am asking a little bit help how i can format my JSON data readable by human?
    something like this:

    Click image for larger version

Name:	Screenshot_13.png
Views:	300
Size:	5.7 KB
ID:	305773

    link of the above ss is here: http://regex.info/code/JSON.lua


    for now what i do is i create a loop to remove and replace:
    filter = {"{", "}", ",", "},"}

    for k,v in pairs (filter) do
    tFilter = String.Find(x, v, 1, false)
    if v == "{" then
    x = String.Replace(x, v, "{\r\n ", false);
    end
    if v == "}" then
    x = String.Replace(x, v, "\r\n }", false);
    end
    if v == "," then
    x = String.Replace(x, v, ",\r\n ", false);
    end
    if v == "}," then
    x = String.Replace(x, v, "},\r\n ", false);
    end
    end

    i know there is another way like in my screenshot, anyone can help? Thank you so much...


    telco


  • #2
    Ok, i think no one will share there thoughts on this..
    so using the script above it can actually works also as this:

    fil = {"{", "}", ",", "},"}
    rep = {"{\r\n ", "\r\n }", ",\r\n ", "},\r\n "}
    for k,v in pairs (fil) do
    if v == fil[k] then
    x = String.Replace(x, v, rep[k], false);
    end
    end

    just to make it few lines..

    you can use it in you JSON format to pretty print.. i know it is not the proper way but it really works..


    Thanks..

    Comment


    • #3
      or even this

      for k,v in pairs (fil) do
      x = String.Replace(x, v, rep[k], false);
      end

      Comment

      Working...
      X