json

A JSON parser and serializer for Carp.

JSON is a sum type with six variants: Null, Bool, Num, Str, Arr, and Obj. Parse JSON strings with JSON.parse, serialize with JSON.str, and access values with JSON.get and JSON.nth.

Parsing

(load "git@github.com:carpentry-org/json@0.1.0")

(defn main []
  (match (JSON.parse "{\"name\": \"carp\"}")
    (Result.Success j) (println* &j)
    (Result.Error e) (IO.errorln &e)))

Building values

(def j (JSON.obj [(JSON.entry @"name" (JSON.Str @"carp"))
                  (JSON.entry @"version" (JSON.Num 1.0))]))