←back to thread

Fixing JSON

(www.tbray.org)
139 points robin_reala | 7 comments | | HN request time: 2.024s | source | bottom
1. lhopki01 ◴[] No.12327755[source]
Just use yaml?
replies(3): >>12327787 #>>12328256 #>>12328267 #
2. wtetzner ◴[] No.12327787[source]
Or if you still want something easy to parse, s-expressions.
replies(1): >>12327927 #
3. omginternets ◴[] No.12327927[source]
Could you please elaborate? I'm vaguely familiar with S-expressions from my cursory inquiry into lisp (planning to take the plunge in November), but I don't see how they can be applied in this context.
replies(1): >>12327996 #
4. nv-vn ◴[] No.12327996{3}[source]
S-expresions are really just a way of representing a tree of data (in Lisp code, the S-expression literally represents the abstract syntax tree that is used for the code).

Take the JSON example:

    {
      "IDs": [116, 943, 234, 38793],
      "Settings": { "Aperture": 2.8, "Shutter speed": "1/250" }
    }
You could rewrite this as an S-expression as:

    ((IDs (116 943 234 3879))
     (Settings
       (Aperture 2.8)
       ("Shutter Speed" "1/250")))
replies(1): >>12328468 #
5. moogly ◴[] No.12328256[source]
YAML is not as simple as one might think. The spec[1] is 80 pages long after all...

1: http://yaml.org/spec/1.2/spec.pdf

6. detaro ◴[] No.12328267[source]
I feel like YAML might be a bit to complicated in the other direction, with many ways of encoding quite complex things and the connected risk for bugs. (E.g. the Python-binding, pyYAML, can't even read its own output correctly in all cases)
7. omginternets ◴[] No.12328468{4}[source]
Thanks! I figured it would be simple, and indeed it was :)