Plus, that can be in addition to having JSON too.
This is the TXR Lisp interactive listener of TXR 271.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
1> '#J{"foo":[1,2,3,"bar"]}
#J{"foo":[1,2,3,"bar"]}
What is that literal syntax?
2> (typeof '#J{"foo":[1,2,3,"bar"]})
cons
cons-cell based object under the hood.
3> (car '#J{"foo":[1,2,3,"bar"]})
json
4> (cadr '#J{"foo":[1,2,3,"bar"]})
quote
It has a (json quote ...) structure.
5> (caddr '#J{"foo":[1,2,3,"bar"]})
#H(() ("foo" #(1.0 2.0 3.0 "bar")))
Followed by a hash table object. We can convert that to a vector to see it all:
6> (vec-list '#J{"foo":[1,2,3,"bar"]})
#(json quote #H(() ("foo" #(1.0 2.0 3.0 "bar"))))
Now actually eval it instead of quoting
7> #J{"foo":[1,2,3,"bar"]}
#H(() ("foo" #(1.0 2.0 3.0 "bar")))
The embedded hash table denoted by the literal is regurgitated.
We can quasiquote JSON:
;; ^ is quasiquote in this dialect not `
1> ^(,(+ 2 2) ,(list 1 2 3))
(4 (1 2 3))
;; cannot use , in JSON for unquoting, so ~ is used:
2> ^#J["foo", ~(+ 2 2.0)]
#J["foo",4]
The quasiquote can be pattern-matched:
3> (match ^#J[~x, ~y] #(1.0 "foo") (list x y))
(1.0 "foo")
Or, using JSON syntax on the right side, which produces the same vector:
4> (match ^#J[~x, ~y] #J[1.0, "foo"] (list x y))
(1.0 "foo")