Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type JSON =
- | JSeq of JSON list
- | JObj of Map<string, JSON>
- | JNum of int
- | JStr of string
- | JBool of bool
- | JNull
- let phone1 = JObj(Map.ofSeq [("type", JStr("home")); ("number", JStr("123 456-789"))])
- let phone2 = JObj(Map.ofSeq [("type", JStr("fax")); ("number", JStr("987 654-321"))])
- let phones = JSeq(List.ofSeq [phone1; phone2])
- let address = JObj(Map.ofSeq [ ("streetAddress", JStr("21 2nd Street")); ("state", JStr("NY")); ("postalCode", JNum(10021)) ])
- let hash = Map.ofSeq [("fisrtName", JStr("Jhon")); ("lastName", JStr("Smith")); ("address", address);("phoneNumbers", phones)]
- let data = JObj(hash)
- let rec show = function
- | JNum(n) -> System.Convert.ToString(n)
- | JBool(b) -> System.Convert.ToString(b)
- | JStr(str) -> "\"" + str + "\""
- | JNull -> "null"
- | JSeq(elems) ->
- let tmp = List.map show elems |> String.concat ", "
- "[" + tmp + "]"
- | JObj(bindings) ->
- let tmp = bindings
- |> Map.toList
- |> List.map (fun (k, v) -> "\"" + k + "\": " + (show v))
- |> String.concat ", "
- "{" + tmp + "}"
- printfn "%s" (show data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement