Showing an individual post.

Io is amazing. Here's a (naive) JSON interpreter in Io.

JSON := Object clone do(
    curlyBrackets := method(
        call message arguments foreach(msg,
            self setSlot(
                call sender doString(msg name),
                JSON clone doMessage(msg next ?next)
            )
        )
        self
    )

    squareBrackets := method(
        call message arguments map(a, JSON clone doMessage(a))
    )
)

JSON clone do(

    {"key" : "value",
     "list" : [1, {"nested" : 42}],
     "nest" : {"key2" : "value2"}}

) slotSummary println

As you can see, the JSON within the do() block is not a string, it's literal JSON which is valid Io syntax.

$ io json.io
 JSON_0x383220:
  key              = "value"
  list             = list(1,  JSON_0x2b1020:
  nested     ...
  nest             = JSON_0x2d12e0
blog comments powered by Disqus