Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON.

Overview

JSONFeed

Swift Version TravisCI Platform Twitter

Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https://jsonfeed.org


⚠️ Contributions are more than welcome! Here is how my todo list looks like now:

  • Implement framework so its usable
  • Proper in-line documentation
  • Clear documentation in README (you are looking at it now)
  • Add CococaPods support
  • Add Carthage support
  • Add SPM support
  • Add CHANGELOG to repository
  • Add much more elaborate tests
  • Add Equtable for objects it makes sense
  • Consider adding byte and date formatter for JSONFeedAttachment

Thanks for checking-out JSONFeed!


Usage

Parsing a feed is super easy; just pass data from a response when creating a feed object and that's it! Parsing happens upon initialization using JSONSerialization and if all goes well you'll be able to access feed properties. In case initialization parameters are invalid, JSONFeed will throw JSONFeedError.

let feed = try? JSONFeed(data: responseData)

Alternatively you can create objects from a JSON string or JSON dictionary:

let dictionary: [String: Any] = ["title": "..."]
let feed = try? JSONFeed(json: dictionary)
let utf8String: String = "{'title':'..."
let feed = try? JSONFeed(jsonString: utf8String)

Documentation

Best way to learn about this library is to browse source files and inline documentation.

Below is quick description of objects and their responsibilities:

Feed and Properties in General

JSONFeed mirrors JSON Feed v1 spec defined keys almost one-to-one. Key names are "Swiftyfied" and strongly typed: all dates will be Date type, URLs — URL and so on. All fields defined by optional in spec are also Swift optionals in all objects.

Items

feed.items is an array of JSONFeedItem objects that wrap your items (posts, episodes for podcasts, etc.). It can not be nil, but can contain 0 elements.

contextText vs contentHTML

According to specs both are optional and both can be present in item at the same time. However if none of them is set by publisher, post will be discarded and not included in items array.

Items with no id

If id for the item is not set by publisher, item will be discarded and not included in items. This happens silently and no error will be thrown. Any other posts with set id will be peresent in array (unless both, contextText and contentHTML are missing). Reason for that in clearly elaborated in Suggestions for Feed Readers of JSON Feed v1 spec:

[...] there is one thing we insist on: any item without an id must be discarded. We come to this from years of experience dealing with feeds in other formats where unique identifiers are optional. Without unique identifiers, it’s impossible to reliably refer to a given item and its changes over time, and this is terrible for user experience and becomes a source of bug reports to you.

Attachments

Items can have attachments, they are wrapped in JSONFeedAttachment object. Attachment can be podcast episode, additional images, or any other media.

You can lear about attachment type using mimeType property. All attachments have url pointing to attached media. Those two are always present in all attachments.

Additionally JSONFeedAttachment have optional size (in bytes) and duration (in seconds) for relevant media files.

Author

Inert JSONFeedAuthor struct with name, avatar URL and web URL. Can be present both in JSONFeedItem and/or in JSONFeed.


Installation

CocoaPods

You can use CocoaPods to install JSONFeed by adding it to your Podfile:

platform :ios, '10.0'
use_frameworks!
pod 'JSONFeed'

Import JSONFeed wherever you plan to parse feed and follow instructions from above.

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/JSONFeed.framework to an iOS project.

github "totocaster/JSONFeed"

Manually

Download and drop all files from Classes folder into in your project.


License

JSONFeed is released under the MIT license. See LICENSE for details.

You might also like...
JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die
JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

JSONNeverDie is an auto reflection tool from JSON to Model, a user friendly JSON encoder / decoder, aims to never die. Also JSONNeverDie is a very important part of Pitaya.

A sweet and swifty YAML parser built on LibYAML.
A sweet and swifty YAML parser built on LibYAML.

Yams A sweet and swifty YAML parser built on LibYAML. Installation Building Yams requires Xcode 11.x or a Swift 5.1+ toolchain with the Swift Package

A lightweight CSS parser for parsing and creating CSS stylesheets

SwiftCSSParser A lightweight CSS parser for Swift that uses cssparser (cpp) under the hood. Basic usage Here's a simple code snippet to get you starte

JSONFeed parser for swift

JSONFeed Swift parsing for JSON Feed Spec Installation Carthage You can install Carthage with Homebrew using the following command: brew update brew i

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 📜 ✍🏻Release Notes: more details Co

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects to and from JSON.

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Comments
  • Having trouble setting up SPM

    Having trouble setting up SPM

    I'm trying to get SPM to work, and I'm worried that we might need to change the file layout.

    If you look at any project that supports SPM, they all have the typical Swift package layout, while this project has the Xcode framework layout.

    I think we should either make a new repo, build on SPM, and the Swift package layout (this thing)

    ├── Package.swift
    ├── Sources
    │   └── hellothere.swift
    └── Tests
        ├── LinuxMain.swift
        └── hellothereTests
            └── hellothereTests.swift
    

    Or, we could just make a fork (or something similar, idk) that completely overwrites everything we had. Or, just not support SPM. (I don't think we should do that however)

    Using my second option we can easily support Linux, all platforms, Carthage and Coccapods, and have a simpler directory format. Obliviously this is completely up to you, as you wrote all the code.

    opened by perryprog 5
Releases(0.8.2)
Owner
Toto Tvalavadze
I make iOS apps, design interfaces, and walk with a camera.
Toto Tvalavadze
Jay - Pure-Swift JSON parser & formatter. Fully streamable input and output. Linux & OS X ready.

Pure-Swift JSON parser & formatter. Fully streamable input and output. Linux & OS X ready. Replacement for NSJSONSerialization.

Danielle 132 Dec 5, 2021
This framework implements a strict JSON parser and generator in Objective-C.

SBJson 5 Chunk-based JSON parsing and generation in Objective-C. Overview SBJson's number one feature is stream/chunk-based operation. Feed the parser

null 3.8k Jan 5, 2023
A JSON parser with concise API written in Swift.

A JSON parser with concise API written in Swift Maps JSON attributes to different Swift types with just two methods: map and mapArrayOfObjects. The li

Evgenii Neumerzhitckii 14 Aug 13, 2018
Functional JSON Parser - Linux Ready

Functional JSON Parser Feature Linux Ready Type-safe JSON parsing Functional value transformation Easy to parse nested value Dependency free No define

Ryo Aoyama 117 Sep 9, 2022
Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend

Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend. Using Argo

thoughtbot, inc. 3.5k Dec 20, 2022
Reddit Feed Built With Swift

RedditFeed Steps to run the application: Download the project. Open Terminal and go to the root of the project. Run pod install Open RedditFeed.xcwork

Rahul Garg 0 Dec 14, 2021
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022
Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Vanesa Giselle Korbenfeld 0 Oct 29, 2021
Ss-json - High-performance json parsing in swift

json 0.1.1 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022