High calorie, easy to digest, JSON mapper in Swift. Just peel and eat.



Banana 🍌 🐒 Build Status Carthage compatible

Banana is a library that allows conversion of parsed JSON into typed objects.

Why another JSON mapper right?

The idea behind creating Banana is to show that JSON mapping is not as complicated.

Simplicity and no-black-magic are the key design principles. The name Banana is chosen to signify this.

If you are interested in how this libary has evolved, please read this blog post series


  • Error handling through do-try-catch mechanism
  • Handles Optionals
  • Supports Keypaths


Only Carthage is supported as of now. Adding CocoaPods support is in pipeline.


To add this library to your project, just add the following to your Cartfile

github "bhargavg/banana"

and carthage update. For full list of command, please refer Carthage documentation


Read a single value

let value: String = try Banana.load(file: "simple") <~~ keyPath("")

Mapping to models and back

        "x": "hi",
        "y": 5
        "x": "yolo",
        "yo": 6
struct Foo {
    let x: String
    let y: Int

    static func fromJSON(json: JSON) throws -> Foo {
        return Foo(
                    x: try get(json, key: "x"),
                    y: try get(json, keys: ["y", "yo"])

    static func toJSON(foo: Foo) -> JSON {
        return ["x": foo.x, "y": foo.y]

let foos: [Foo] = try Banana.load(file: "foos_file") <<~ Foo.fromJSON

let jsonString: String = try foos <<~ Foo.toJSON <~~ Banana.dump(options: [.PrettyPrinted]) <~~ Banana.toString(encoding: NSUTF8StringEncoding)


  • Carthage Support
  • CocoaPods Support
  • SwiftPM Support
  • OS X, iOS Targets
  • Watch, TvOS Targets


Found a bug? Want a new feature? Please feel free to report any issue or raise a Pull Request.