Re: JSON / XML support in E
Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]> Thu, 08 Sep 2011 15:13:31 +0100
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
On 2011-09-08 14:33, Kevin Reid wrote: > On Sep 8, 2011, at 8:21, Thomas Leonard wrote: >> On further investigation, it seems that newlines aren't allowed in JSON >> strings anyway: >> >> http://stackoverflow.com/questions/42068/how-do-i-handle-newlines-in-json >> >> This patch turns newlines into "\n" sequences and doesn't quote "'" >> (which JSON also doesn't allow): >> >> http://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/1b0a82891d305059c3732bc33b6702b41e944acf >> >> I spotted these problems when trying to parse E's JSON output using >> Python. The changes also fix<elib:serial.deJSONKit>. > > Looks OK, but please audit other users of StringHelper to see if any need it the other way. > > I would object to escaping newlines for the readability reduction, except that not doing so means that pretty-printing indentation changes the content, which is a bug. Note that there are (now) two methods in StringHelper: - quote is mostly as before, except it no longer escapes "'" - the new quoteIncludingNewline method also quotes newlines The change to "quote" isn't strictly necessary, but it seemed sensible and better than trying to explain why the two methods handled "'" differently. This causes the following change: ? "'foo'\n'bar'" Before: # value: "\'foo\' # \'bar\'" After: # value: "'foo' # 'bar'" -- Dr Thomas Leonard IT Innovation Centre Gamma House, Enterprise Road, Southampton SO16 7NS, UK tel: +44 23 8059 8866 mailto:tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected] http://www.it-innovation.soton.ac.uk/