> If I send a JSON { 'str': '<p>This is a line with \n linefeed</p>' } I do 
> get...

You haven't mentioned what language you're using to write out the
string (PHP, Python, JavaScript, C#, Java, etc.), but my suspicion is
that you're accidentally outputting an actual newline (character x0A)
rather than the valid JSON[1] syntax for it (\n), because in most
languages, the backslash is an escape character and to actually output
"\n" you'd have to type "\\n".

For instance (pure JavaScript example):

    var s;

    s = '{"foo": "This is a \n test."}';
    alert(s.isJSON()); // alerts false, the string is not valid JSON

    s = '{"foo": "This is a \\n test."}';
    alert(s.isJSON()); // alerts true, the string is valid JSON

The JSON going to the browser (which you can probably inspect with
Firebug or the MS Dev Toolbar or whatever you're using) must contain
an actual backslash followed by the letter n, *not* a literal newline.

[1] http://json.org

T.J. Crowder
Independent Software Consultant
tj / crowder software / com

On Nov 10, 9:31 pm, Manfred Rebentisch <mrebenti...@comparat.de>
> I have a question to this prototype function:
>   function isJSON() {
>     var str = this;
>     if (str.blank()) return false;
>     str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
>     return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
>   }
> If I send a JSON { 'str': '<p>This is a line with \n linefeed</p>' } I do get
> an error. The same is, if the JSON is encoded to { 'str': '<p>This is a line
> with %0A linefeed</p>' }.
> I need to delete the linefeed or I need to replace to '<br />'.
> I do not understand the regular expression above, because I want avoid to use
> other chars, which results in errors.
> Manfred
> --http://www.comparat.dehttp://www.athesios.dehttp://twitter.com/COMPARAT
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to