JSON::Feed - Syndication with JSON.
Parsing:
JSON::Feed->from_string( $json_text );
Generating:
# Initialize, with some content. my $feed = JSON::Feed->new( title => "An example of JSON feed", feed_url => "https://example.com/feed.json", items => [ +{ id => 42, url => 'https://example.com/item/42', summary => 'An item with some summary', date_published: "2019-03-06T09:24:03+09:00" }, +{ id => 623, url => 'https://example.com/item/623', summary => 'An item with some summary', date_published: "2019-03-07T06:22:51+09:00" }, ] ); # Mutate $feed->set( description => 'Some description here.' ); $feed->add_item( id => 789, title => "Another URL-less item here", summary => "Another item here. Lorem ipsum yatta yatta yatta.", ); # Output print $fh $feed->to_string;
JSON Feed is a simple format for website syndication with JSON, instead of XML.
This module implements minimal amout of API for parsing and/or generating such feeds. The users of this module should glance over the jsonfeed spec in order to correctly generate a JSON::Feed.
Here's a short but yet comprehensive Type mapping between jsonfeed spec and perl.
| jsonfeed | perl | |----------+----------------------------| | object | HashRef | | boolean | JSON::true, or JSON::false | | string | Str | | array | ArrayRef |
The $attr here must be a name from one top-level attribute from v1 spec.
$attr
The passed $value thus must be the corresponding value.
$value
Most of the values from spec are strings and that maps to a perl scalar veraible. The term `object` in the spec is mapped to a perl HashRef.
Be aware that the spec allows feed extensions by prefixng attributes with underscore character. Thus, all strings begin with '_' are valid. Whatever those extented attributes mapped to are left as-is.
'_'
Retrieve the value of the given top-level varible.
Apend the given $item to the items attribute. The type of input $item is described in the "Items" section of the spec.
$item
items
Stringify this JSON Feed. At this moment, the feed structure is checked and if it is invalid, an exception is thrown.
Take a reference to a string that is assumed to be a valid json feed and produce an object from it. Exception will be thrown if the input is not a valid JSON feed.
This method is supposed to be consume the output of to_string method without throwing exceptions.
to_string
JSON Feed spec v1 https://jsonfeed.org/version/1
Kang-min Liu <gugod@gugod.org>
CC0
To install JSON::Feed, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::Feed
CPAN shell
perl -MCPAN -e shell install JSON::Feed
For more information on module installation, please visit the detailed CPAN module installation guide.