From: Oren Ben-K. <or...@be...> - 2006-04-14 17:02:05
|
On Friday 14 April 2006 19:32, Kirill Simonov wrote: > By the way, does JSON allow multiline scalars, like > "foo > bar" ? > It's not clear from the production rules on json.org. It depends on > whether line breaks are control characters or not. Clark raised the same issue. Standard practice is that control == all chars less than ASCII space, this includes Control-J (\n) and Control-M (\r). Unicode has character classes, including "control" chars, and again line breaks are control characters. So its pretty unambiguous. JSON does _not_ allow raw line breaks in strings. > > Now I wonder though is this restriction JSON compatible? Hmmm... It turns out it just _almost_ is. Nice catch! JSON does allow: {"foo": 123} This is invalid YAML (now) because we never let scalar content be unindented (we require at least one space). The reason is, as I pointed out in the start of the thread, to allow us to trivially chop a YAML stream to documents without having to parse it first. Now, since JSON requires all strings to be quoted, and doesn't allow a raw line break in a string, this actually isn't a problem. The new rules will allow the " to be unindented, and its safe. The problem is that we need to allow the unindented 123 above. Plain scalars already may appear unindented, e.g.: --- foo: # Unindented plain scalar ... And we cover that already, so that: --- { foo: } ... Will be OK too - I just need to take care the productions agree. Whew. Thanks for pointing this out. Have fun, Oren Ben-Kiki |