Implementing JSON Feed

20/09/2018 18:41 BST

A little while ago, I have implemented a JSON feed for my blog entries, I could of also implemented RSS and Atom as well, but I really want to avoid using XML because of its complexity so instead of that of just have JSON feed, to be frank I hate XML with a passion.

It’s live at https://www.cj-jackson.com/feed.json all working nicely. It’s was easy to implement, soo easy I can show you the source code in Go.

package frontJsonFeed

import "time"

const (
	Version1 = "https://jsonfeed.org/version/1"

	ContentType = "application/json"
)

type Feed struct {
	Version     string `json:"version"`
	Title       string `json:"title"`
	HomePageUrl string `json:"home_page_url"`
	FeedUrl     string `json:"feed_url"`
	Items       []Item `json:"items"`
}

type Item struct {
	Id            string     `json:"id"`
	Url           string     `json:"url"`
	Title         string     `json:"title"`
	ContentHtml   string     `json:"content_html"`
	DatePublished time.Time  `json:"date_published"`
	DateModified  *time.Time `json:"date_modified,omitempty"`
}

func CheckTime(t time.Time) *time.Time {
	if t.IsZero() {
		return nil
	}

	return &t
}

If I build an API, it’s will also be in JSON, as it’s is the future, I would rather stop idling with the past, that is XML.

I left a hint on one reason of the reasons why I would never consider buying a Mac!!

| |