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
BoolFloat32(aka.Float),Float64(aka.Double)Int,Int8,Int16,Int32,Int64StringUInt,UInt8,UInt16,UInt32,UInt64URL
Type Erasing Objects
Containers
JSONArray<T>:[T]JSONDictionary<T>:[String: T]JSONNull<T>:nil: T?(use when the value isnull)JSONNullable<T>:T?(use when the value can benull)JSONOptional<T>:T?(use when the value might not be in the JSON)
Others
DiscardJSON:VoidJSONRawRepresentable: a protocol to auto-implementJSONDeserializablefor your enums with raw valuesJSONRepresentable: a protocol to reduce self-deserializing types’ boiler-plate to atypealiasand an initialiser
View on GitHub
Install in Dash
StrongJSON Reference