JSONFeed is a library for creating and parsing JSONFeed feeds.
String jsonFeedString = "{ ... }";
// Parse the JSON feed string
Feed feed = DefaultFeed.fromString(jsonFeedString);
// Get some fields from the feed
Version version = feed.getVersion();
String title = feed.getTitle();
String description = feed.getDescription();
URL homePageUrl = feed.getHomePageUrl();
URL feedUrl = feed.getFeedUrl();
// Get the item list from the feed
List<Item> itemList = feed.getItemList()
// Create a new item
Item item = new DefaultItem("1")
.setTitle("First Item")
.setSummary("First item summary.")
.setUrl(new URL("https://somehost.com/article/1"));
// Create an item list and add the item
List<Item> itemList = new ArrayList<Item>();
itemList.add(item);
// Create a new feed
Feed feed = new DefaultFeed()
.setTitle("Feed Title")
.setDescription("Feed Description")
.setHomePageUrl(new URL("https://somehost.com/"))
.setFeedUrl(new URL("https://somehost.com/feed.json"));
// Add the item list to the feed
feed.setItemList(itemList);
// Get the feed as a JSON feed string
String jsonFeedString = feed.toJSONString()
This library supports both JSONFeed 1.0 and 1.1, and there is support for 'upgrading' a feed from version 1.0 to 1.1. Additionally the parser will inspect the feed and upgrade it if needed.
This depends on JSON-java for JSON parsing and creation.
Thanks go to Martin McCallion (@devilgate) and his devilgate/pertwee project for inspiring this.