comparison json.ur @ 1:4d103b4450ee

Converted a record to JSON
author Adam Chlipala <adam@chlipala.net>
date Thu, 02 Dec 2010 11:35:01 -0500
parents 63697ef80a2c
children 478524b9d23a
comparison
equal deleted inserted replaced
0:63697ef80a2c 1:4d103b4450ee
188 end 188 end
189 in 189 in
190 {ToJson = toJ, 190 {ToJson = toJ,
191 FromJson = fromJ} 191 FromJson = fromJ}
192 end 192 end
193
194 fun json_record [ts ::: {Type}] (fl : folder ts) (jss : $(map json ts)) (names : $(map (fn _ => string) ts)) : json $ts =
195 {ToJson = fn r => "{" ^ @foldR3 [json] [fn _ => string] [id] [fn _ => string]
196 (fn [nm ::_] [t ::_] [r ::_] [[nm] ~ r] (j : json t) name v acc =>
197 escape name ^ ":" ^ j.ToJson v ^ (case acc of
198 "" => ""
199 | _ => "," ^ acc))
200 "" fl jss names r ^ "}",
201 FromJson = fn _ => error <xml>Uhoh!</xml>}