-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example for constructing json
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(* | ||
dune exec examples/constructing.exe <<EOF | ||
{ | ||
"id": "398eb027", | ||
"name": "John Doe", | ||
"pages": [ | ||
{ | ||
"id": 1, | ||
"title": "The Art of Flipping Coins", | ||
} | ||
] | ||
} | ||
EOF | ||
*) | ||
|
||
open Yojson.Basic.Util | ||
|
||
let json_output = | ||
`Assoc | ||
[ | ||
("id", `String "398eb027"); | ||
("name", `String "John Doe"); | ||
( "pages", | ||
`Assoc | ||
[ ("id", `Int 1); ("title", `String "The Art of Flipping Coins") ] ); | ||
] | ||
|
||
let main () = | ||
let oc = stdout in | ||
Yojson.Basic.pretty_to_channel oc json_output; | ||
output_string oc "\n"; | ||
close_out oc | ||
|
||
let () = main () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters