OCaml library for JSONfeed parsing and creation
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 = Item.create 9 ~id:"https://example.com/1" 10 ~title:"Test Item" 11 ~content:(`Html "<p>Hello, world!</p>") 12 () in 13 14 let feed = Jsonfeed.create 15 ~title:"Test Feed" 16 ~home_page_url:"https://example.com" 17 ~authors:[author] 18 ~items:[item] 19 () in 20 21 (* Serialize to JSON *) 22 let json = match Jsonfeed.to_string feed with 23 | Ok s -> s 24 | Error e -> failwith (Jsont.Error.to_string e) 25 in 26 27 (* Print it *) 28 Printf.printf "Generated JSON Feed:\n%s\n\n" json; 29 30 (* Validate *) 31 match Jsonfeed.validate feed with 32 | Ok () -> Printf.printf "✓ Feed is valid\n" 33 | Error errors -> 34 Printf.printf "✗ Feed has errors:\n"; 35 List.iter (Printf.printf " - %s\n") errors