Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Latest commit

 

History

History
87 lines (62 loc) · 3.23 KB

README.md

File metadata and controls

87 lines (62 loc) · 3.23 KB

StrongJSON

StrongJSON is a Swift framework to help deserialize complex JSON objects.

Its biggest advantage over other frameworks is that during deserialization, types are checked and data is validated. If no exception occured during deserialization, the resulting Swift objects are guarenteed to be well formed.

With StrongJSON, you'll handle all JSON errors at once.
No more checking for nil, or accessing a value using .string, .int or crazy operators!

For more information, check out the docs.

Example

// The type annotations are not required, they're just
// here to make the results explicit.

let n: Int = try Int.parseJSON("0")

let digits: [UInt8] = try JSONArray<UInt8>.parseJSON(
	"[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]"
)

let ascii: [String: UInt8] = try JSONDictionary<UInt8>.parseJSON(
	"{ \"A\": 65, \"B\": 66 }"
)

The following examples all throw exceptions:

try UInt.parseJSON("-1")
try UInt.parseJSON("true")
try UInt8.parseJSON("256")

For an example with a class, see UsageTests.swift.
For one with an enum, see JSONRawRepresentable.

JSONDeserializer Implementing Types

Format: Deserializer[: OutputType], where OutputType defaults to Deserializer.

Stdlib

  • Bool
  • Float32 (aka. Float), Float64 (aka. Double)
  • Int, Int8, Int16, Int32, Int64
  • String
  • UInt, UInt8, UInt16, UInt32, UInt64
  • URL

Type Erasing Objects

Containers

Others