t_yojson.ml 596 B

123456789101112131415161718192021222324
  1. (*
  2. * https://github.com/ocaml-community/yojson/blob/master/examples/constructing.ml
  3. *)
  4. let test_constructing () =
  5. `Assoc
  6. [
  7. ("id", `String "398eb027");
  8. ("name", `String "John Doe");
  9. ( "pages",
  10. `Assoc
  11. [ ("id", `Int 1); ("title", `String "The Art of Flipping Coins") ] );
  12. ]
  13. |> Yojson.Basic.pretty_to_string
  14. |> Assrt.equals_string __LOC__
  15. "{\n\
  16. \ \"id\": \"398eb027\",\n\
  17. \ \"name\": \"John Doe\",\n\
  18. \ \"pages\": { \"id\": 1, \"title\": \"The Art of Flipping Coins\" }\n\
  19. }"
  20. let () =
  21. test_constructing ();
  22. assert true