OCaml library for JSONfeed parsing and creation
README.md
# OCaml-JSONFeed An OCaml library for parsing and generating [JSON Feed](https://www.jsonfeed.org/) documents. JSON Feed is a format similar to RSS and Atom but uses JSON instead of XML. It is designed to be easier for developers to work with while providing all the functionality needed for feed syndication. ## Installation Add to your `dune-project`: ```lisp (package (name your-package) (depends jsonfeed ...)) ``` ## Quick Start ### Creating a Feed ```ocaml open Jsonfeed (* Create an author *) let author = Author.create ~name:"Jane Doe" ~url:"https://example.com/jane" () (* Create an item with HTML content *) let item = Item.create ~id:"https://example.com/posts/1" ~url:"https://example.com/posts/1" ~title:"Hello, JSON Feed!" ~content:(`Html "<p>My first post using JSON Feed.</p>") ~authors:[author] ~tags:["introduction"; "jsonfeed"] () (* Create the feed *) let feed = Jsonfeed.create ~title:"My Blog" ~home_page_url:"https://example.com" ~feed_url:"https://example.com/feed.json" ~items:[item] () (* Serialize to JSON *) let json = Jsonfeed.to_string feed ``` ### Parsing a Feed ```ocaml open Jsonfeed (* Parse from string *) match Jsonfeed.of_string json_string with | Ok feed -> Printf.printf "Feed: %s\n" (Jsonfeed.title feed); List.iter (fun item -> match Item.title item with | Some title -> Printf.printf "- %s\n" title | None -> () ) (Jsonfeed.items feed) | Error err -> Printf.eprintf "Parse error: %s\n" err (* Parse from file *) let content = In_channel.with_open_text "feed.json" In_channel.input_all in match Jsonfeed.of_string content with | Ok feed -> (* ... *) | Error _ -> (* ... *) ``` ### Content Types Items can have HTML content, plain text content, or both: ```ocaml (* HTML only *) let item1 = Item.create ~id:"1" ~content:(`Html "<p>Rich <strong>HTML</strong> content</p>") () (* Plain text only *) let item2 = Item.create ~id:"2" ~content:(`Text "Plain text content") () (* Both HTML and text *) let …