···
+
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.
+
Add to your `dune-project`:
+
let author = Author.create
+
~url:"https://example.com/jane"
+
(* Create an item with HTML content *)
+
~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>")
+
~tags:["introduction"; "jsonfeed"]
+
let feed = Jsonfeed.create
+
~home_page_url:"https://example.com"
+
~feed_url:"https://example.com/feed.json"
+
(* Serialize to JSON *)
+
let json = Jsonfeed.to_string feed
+
(* Parse from string *)
+
match Jsonfeed.of_string json_string with
+
Printf.printf "Feed: %s\n" (Jsonfeed.title feed);
+
match Item.title item with
+
| Some title -> Printf.printf "- %s\n" title
+
) (Jsonfeed.items feed)
+
Printf.eprintf "Parse error: %s\n" err
+
let content = In_channel.with_open_text "feed.json" In_channel.input_all in
+
match Jsonfeed.of_string content with
+
Items can have HTML content, plain text content, or both:
+
let item1 = Item.create
+
~content:(`Html "<p>Rich <strong>HTML</strong> content</p>")
+
let item2 = Item.create
+
~content:(`Text "Plain text content")
+
(* Both HTML and text *)
+
let item3 = Item.create
+
~content:(`Both ("<p>HTML version</p>", "Text version"))
+
match Item.content_html item1 with
+
| Some html -> Printf.printf "HTML: %s\n" html
+
### Podcast Feed with Attachments
+
(* Create an audio attachment *)
+
let episode_audio = Attachment.create
+
~url:"https://podcast.example.com/ep1.mp3"
+
~mime_type:"audio/mpeg"
+
~size_in_bytes:15_728_640L
+
~duration_in_seconds:1800
+
(* Create a podcast episode *)
+
let episode = Item.create
+
~id:"https://podcast.example.com/episodes/1"
+
~title:"Episode 1: Introduction"
+
~content:(`Html "<p>Welcome to the show!</p>")
+
~attachments:[episode_audio]
+
The `example/` directory contains several complete examples:
+
- **feed_example.ml** - Creating and serializing feeds (blog and podcast)
+
- **feed_parser.ml** - Parsing and analyzing feeds from files
+
- **feed_validator.ml** - Validating feeds and demonstrating various feed types
+
opam exec -- dune exec -- ./example/feed_parser.exe
+
opam exec -- dune exec -- ./example/feed_example.exe
+
Build the API documentation:
+
opam exec -- dune build @doc
+
Then open `_build/default/_doc/_html/index.html` in your browser.
+
This library implements [JSON Feed Version 1.1](https://www.jsonfeed.org/version/1.1/).
+
See LICENSE.md for details.