OCaml library for JSONfeed parsing and creation
at v1.1.0 880 B view raw
1(** Simple test to demonstrate JSON serialization works *) 2 3open Jsonfeed 4 5let () = 6 (* Create a simple feed *) 7 let author = Author.create ~name:"Test Author" () in 8 let item = 9 Item.create ~id:"https://example.com/1" ~title:"Test Item" 10 ~content:(`Html "<p>Hello, world!</p>") () 11 in 12 13 let feed = 14 Jsonfeed.create ~title:"Test Feed" ~home_page_url:"https://example.com" 15 ~authors:[ author ] ~items:[ item ] () 16 in 17 18 (* Serialize to JSON *) 19 let json = 20 match Jsonfeed.to_string feed with 21 | Ok s -> s 22 | Error e -> failwith (Jsont.Error.to_string e) 23 in 24 25 (* Print it *) 26 Printf.printf "Generated JSON Feed:\n%s\n\n" json; 27 28 (* Validate *) 29 match Jsonfeed.validate feed with 30 | Ok () -> Printf.printf "✓ Feed is valid\n" 31 | Error errors -> 32 Printf.printf "✗ Feed has errors:\n"; 33 List.iter (Printf.printf " - %s\n") errors