Latest 0.1.0
Homepage https://github.com/AV8R-/JSONPath
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform
Swift

JSONPath is simple library for parsing complicate JSON structures

Requirements

Swift 4.2

Installition

JSONPath is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'JSONPath'

Benefits

Let’s we have the struct:

struct Person: Codable {
  let name: String
  let age: Int
}

and the JSON:

{
  "payload": {
    "persons": [
      {
        "name": "Ed",
        "age": "39"
      },
      {
        "name": "Keily",
        "age": "37"
      }
    ]
  }
}

There are few ways to got the struct from the JSON

  1. Refuse Codable and parse it with any of 3rd party parsing library manually
  2. Use Codable but create 2 extra structs. Or 1 extra struct with custom init
  3. Using JSONPath simple call through JSON path and get array of Codable persons

Quick Start

The base struct of the library is JSONTree. Objects of this type are initialized with JSON Data.

let json = [
  "payload": [
    "persons": [
      [
        "name": "Ed",
        "age": "39"
      ],
      [
        "name": "Keily",
        "age": "37"
      ]
    ]
  ]
]
let jsonData = try JSONSerialization.data(withJSONObject: json, options: [])
let jsonTree = try JSONTree(data: jsonData)

It supports dynamicMemberLookup . To parse array of Person :

let persons: [Person]? = tree.payload?.persons?.value()

And you can subscribe by index:

let person: Person? = tree.payload?.persons?[0]?.value()

Contribute

If you want to help improve this library you can take on of the opened tasks:

  1. Setup Travis CI
  2. Exceptions instead of Optional result
  3. Carthage support

Author

Bogdan Manshilin, [email protected]

License

JSONPath is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "JSONPath",
    "version": "0.1.0",
    "summary": "The most simple JSON parsing for Swift.",
    "description": "JSONPath is JSON parsing libriry that relies on cutting edge technologies of Swift. It uses dynamicMemberLookup and Codable.",
    "homepage": "https://github.com/AV8R-/JSONPath",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Bogdan Manshilin": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AV8R-/JSONPath.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.2",
    "source_files": "JSONPath/Classes/**/*"
}

Pin It on Pinterest

Share This