Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Json module eating escaped newlines, tabs returns and such. — Gideros Forum

Json module eating escaped newlines, tabs returns and such.

AniketAniket Member
edited April 2016 in General questions
The json module will eat any newlines in strings even if they were appropriately quoted.
The bottom line is that if you have json formatted text, with properly quoted newlines, decoding that text to json will eliminate encoded newlines and other characters that should be preserved, replacing them with one space and if it was a newline, it will be converted to " n". Tabs become a space and a t so \\t = " t".

I tried to track it down and even though I might have massively misunderstood:

For the file:
./plugins/json/source/lua_cjson.c
Line 413 designates newlines, tabs, returns are whitespace.
Line 1017 eats all designated whitespace characters. Effectively replacing them with spaces......I think.


Comments

  • ar2rsawseenar2rsawseen Maintainer
    Can you provide an example which fails for you?

    I just did a quick test like:
    require "json"
    local encoded = json.encode({text="Some text with\nnew line"})
     
    print(encoded)
    print(json.decode(encoded).text)
    and it seems to be working correctly, outputting
    {"text":"Some text with\nnew line"}
    Some text with
    new line
Sign In or Register to comment.