hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

JSON Closer to YAML, But No Cigar (Thanks Alot, Whitespace!) #

by why in inspect

A while ago, I had an epiphany about all JSON being valid YAML. Great news, right? You get two formats for one. This issue has undergone further scrutiny and, as usual, there is good news and bad news.

Douglas Crockford, the founder of JSON has removed /* .. */ comments from the JSON specification, which was identified as the singular incompatibility between JSON and YAML. In addition, single-quoted strings were removed which YAML handled differently (in terms of escaping.) So, this is good for unifying the two.

However, another minor difference has been found. In JSON structures, the colon and comma need not be spaced out between items in a collection. In YAML, they do. Observe:

 # valid JSON, also valid YAML
 {"nick": "Philarp Tremaine", "rank": "infantry", 
  "badge": "orange-striped, syrup-scented"}

 # valid JSON, not valid YAML
 {"nick":"Philarp Tremaine","rank":"infantry", 
  "badge":"orange-striped, syrup-scented"}

YAML requires the space after each colon or comma. This is because YAML supports commas and colons in plain, unquoted strings.

 # valid YAML, not valid JSON
 {nick: Philarp Tremain, walked: 1,000 miles,
  blog: http://courageousandwarstained.blogspot.com}

For now, if you’re using Syck to parse JSON, be sure the JSON outputter you’re using is YAML-safe JSON. Clark and Doug are working to find a middle-ground and the spotlight is on YAML’s buzzer finger right now. I’ll let ya know how it goes.

said on 14 Nov 2005 at 14:41

Come on mang, you can spell “a lot”!

said on 14 Nov 2005 at 17:45

Come on, Bob, can’t you smell the irony?

said on 14 Nov 2005 at 19:53

I couldn’t allot the spelling sensibil’ties. `weep`

said on 15 Nov 2005 at 08:07

Glass-house Bob, your exclamation point should be on the other side of the closing double quote. But we’re not nitpicky here…

said on 16 Nov 2005 at 16:24

I thought that the punctuation with quotes rules were sort of flexible, at least in some schools of thought.

said on 16 Nov 2005 at 22:44

Wikipedia says the American convention is for sentence punctuation to be included inside the quotation marks, even if the punctuation is not part of the quoted sentence, while the British style is to have the punctuation outside the quotation marks for small quoted phrases. ref

Comments are closed for this entry.