Skip to content

JSON Feed Reference

JSON Feed is a syndication format based on JSON that provides a simple, straightforward way to publish feeds. Feedsmith provides full parsing and generation capabilities.

Versions1.0, 1.1
SpecificationJSON Feed 1.1 Specification
NamespacesNone (JSON-based format)

Functions

parseJsonFeed()

Parses JSON Feed content and returns a typed JSON Feed object.

typescript
import { parseJsonFeed } from 'feedsmith'

const jsonFeed = parseJsonFeed(jsonContent)
// Returns: object with all fields optional and dates as strings

// Limit number of items parsed
const jsonFeed = parseJsonFeed(jsonContent, { maxItems: 10 })

Parameters

ParameterTypeDescription
contentstringThe JSON Feed content to parse
optionsobjectOptional parsing settings

Options

OptionTypeDefaultDescription
maxItemsnumber-Limit the number of items parsed. Use 0 to skip items entirely, useful when only feed metadata is needed

Returns

object - Parsed JSON Feed with all fields optional and dates as strings

generateJsonFeed()

Generates JSON Feed from feed data.

typescript
import { generateJsonFeed } from 'feedsmith'

const json = generateJsonFeed(feedData)

Parameters

ParameterTypeDescription
dataobjectJSON Feed data to generate
optionsobjectOptional generation settings

Options

OptionTypeDefaultDescription
strictbooleanfalseEnable strict mode for spec-required field validation, see Strict Mode

Returns

object - Generated JSON Feed

detectJsonFeed()

Detects if the provided content is a JSON Feed.

Parameters

ParameterTypeDescription
contentstringThe content to check

Returns

boolean - true if content appears to be JSON Feed format

Example

typescript
import { detectJsonFeed } from 'feedsmith'

const isJsonFeed = detectJsonFeed(jsonContent)

Types

All JSON Feed types are available under the Json namespace:

typescript
import type { Json } from 'feedsmith'

// Access any type from the definitions below
type Feed = Json.Feed<Date>
type Item = Json.Item<Date>
type Author = Json.Author
type Attachment = Json.Attachment
// … see type definitions below for all available types

See the TypeScript guide for usage examples.

Type Definitions

INFO

For details on type parameters (TDate, TStrict) and Requirable<T> markers, see TypeScript Reference.

ts
export namespace Json {
  export type Author = {
    name?: string
    url?: string
    avatar?: string
  }

  export type Attachment<TStrict extends boolean = false> = Strict<
    {
      url: Requirable<string> // Required in spec.
      mime_type: Requirable<string> // Required in spec.
      title?: string
      size_in_bytes?: number
      duration_in_seconds?: number
    },
    TStrict
  >

  export type Item<TDate extends DateLike, TStrict extends boolean = false> = Strict<
    {
      id: Requirable<string> // Required in spec.
      url?: string
      external_url?: string
      title?: string
      content_html?: string // At least one of content_html or content_text is required in spec.
      content_text?: string // At least one of content_html or content_text is required in spec.
      summary?: string
      image?: string
      banner_image?: string
      date_published?: TDate
      date_modified?: TDate
      tags?: Array<string>
      authors?: Array<Author>
      language?: string
      attachments?: Array<Attachment<TStrict>>
    },
    TStrict
  > &
    (TStrict extends true ? { content_html: string } | { content_text: string } : unknown)

  export type Hub<TStrict extends boolean = false> = Strict<
    {
      type: Requirable<string> // Required in spec.
      url: Requirable<string> // Required in spec.
    },
    TStrict
  >

  export type Feed<TDate extends DateLike, TStrict extends boolean = false> = Strict<
    {
      title: Requirable<string> // Required in spec.
      home_page_url?: string
      feed_url?: string
      description?: string
      user_comment?: string
      next_url?: string
      icon?: string
      favicon?: string
      language?: string
      expired?: boolean
      hubs?: Array<Hub<TStrict>>
      authors?: Array<Author>
      items: Requirable<Array<Item<TDate, TStrict>>> // Required in spec.
    },
    TStrict
  >
}