comparison json.ur @ 4:8f7396495045

JSON nulls
author Adam Chlipala <adam@chlipala.net>
date Thu, 02 Dec 2010 12:27:30 -0500
parents 189245a3c075
children 6cd839818393
comparison
equal deleted inserted replaced
3:189245a3c075 4:8f7396495045
137 (True, String.substring s {Start = 4, Len = String.length s - 4}) 137 (True, String.substring s {Start = 4, Len = String.length s - 4})
138 else if String.isPrefix {Full = s, Prefix = "false"} then 138 else if String.isPrefix {Full = s, Prefix = "false"} then
139 (False, String.substring s {Start = 5, Len = String.length s - 5}) 139 (False, String.substring s {Start = 5, Len = String.length s - 5})
140 else 140 else
141 error <xml>JSON: bad boolean string: {[s]}</xml>} 141 error <xml>JSON: bad boolean string: {[s]}</xml>}
142
143 fun json_option [a] (j : json a) : json (option a) =
144 {ToJson = fn v => case v of
145 None => "null"
146 | Some v => j.ToJson v,
147 FromJson = fn s => if String.isPrefix {Full = s, Prefix = "null"} then
148 (None, String.substring s {Start = 4, Len = String.length s - 4})
149 else
150 let
151 val (v, s') = j.FromJson s
152 in
153 (Some v, s')
154 end}
142 155
143 fun json_list [a] (j : json a) : json (list a) = 156 fun json_list [a] (j : json a) : json (list a) =
144 let 157 let
145 fun toJ' (ls : list a) : string = 158 fun toJ' (ls : list a) : string =
146 case ls of 159 case ls of