annotate tests/testJson.ur @ 2:478524b9d23a

Parsed a JSON record
author Adam Chlipala <adam@chlipala.net>
date Thu, 02 Dec 2010 11:59:55 -0500
parents 4d103b4450ee
children 189245a3c075
rev   line source
adam@1 1 open Json
adam@1 2
adam@1 3 val json_abcd : json {A : int, B : float, C : string, D : bool} =
adam@1 4 json_record {A = "a", B = "b", C = "c", D = "d"}
adam@1 5
adam@2 6 fun main () : transaction page =
adam@2 7 d <- return (fromJson "{\"a\": 1, \"b\": 2.3, \"c\": \"Hi\", \"d\": true}" : {A : int, B : float, C : string, D : bool});
adam@2 8 return <xml><body>
adam@2 9 {[toJson (1 :: 2 :: 8 :: [])]}<br/>
adam@2 10 {[fromJson "[1,2, 8]" : list int]}
adam@2 11 <hr/>
adam@2 12 {[toJson (1.2 :: 2.4 :: (-8.8) :: [])]}<br/>
adam@2 13 {[fromJson "[1.4,-2.7, 8.215506]" : list float]}
adam@2 14 <hr/>
adam@2 15 {[toJson ("hi" :: "bye" :: "tricky\\\" one!" :: [])]}<br/>
adam@2 16 {[fromJson "[\"abc\", \"\\\\whoa\"]" : list string]}
adam@2 17 <hr/>
adam@2 18 {[toJson (True :: False :: True :: [])]}<br/>
adam@2 19 {[fromJson "[true,false, true]" : list bool]}
adam@2 20 <hr/>
adam@2 21 {[toJson {A = 1, B = 2.3, C = "Hi", D = True}]}<br/>
adam@2 22 A: {[d.A]}, B: {[d.B]}, C: {[d.C]}, D: {[d.D]}
adam@2 23 </body></xml>