0001    //
0002    //  JSON.swift
0003    //  PMJSON
0004    //
0005    //  Created by Kevin Ballard on 10/8/15.
0006    //  Copyright © 2016 Postmates.
0007    //
0008    //  Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
0009    //  http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
0010    //  <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
0011    //  option. This file may not be copied, modified, or distributed
0012    //  except according to those terms.
0013    //
0014    
0015    /// A single JSON-compatible value.
0016    public enum JSON
Accessors.swift:15
public extension JSON {
Accessors.swift:81
public extension JSON {
Accessors.swift:144
public extension JSON {
Accessors.swift:177
public extension JSON {
DecimalNumber.swift:21
    public extension JSON {
DecimalNumber.swift:96
    public extension JSON {
DecimalNumber.swift:145
    public extension JSON {
Decoder.swift:15
extension JSON {
Decoder.swift:20
    public static func decode(string: Swift.String, strict: Swift.Bool = false) throws -> JSON {
Decoder.swift:31
    public static func decode<Seq: SequenceType where Seq.Generator.Element == UnicodeScalar>(scalars: Seq, strict: Swift.Bool = false) throws -> JSON {
Decoder.swift:45
    mutating func decode() throws -> JSON {
Decoder.swift:61
    private mutating func buildValue() throws -> JSON {
Decoder.swift:77
    private mutating func buildObject() throws -> JSON {
Decoder.swift:79
        var dict: [String: JSON] = Dictionary(minimumCapacity: objectHighWaterMark)
Decoder.swift:96
    private mutating func buildArray() throws -> JSON {
Encoder.swift:15
extension JSON {
Encoder.swift:20
    public static func encodeAsString(json: JSON, pretty: Swift.Bool = false) -> Swift.String {
Encoder.swift:30
    public static func encode<Target: OutputStreamType>(json: JSON, inout toStream stream: Target, pretty: Swift.Bool = false) {
Encoder.swift:34
    private static func encode<Target: OutputStreamType>(json: JSON, inout toStream stream: Target, indent: Int?) {
JSON.swift:35
public typealias JSONArray = ContiguousArray<JSON>
JSON.swift:37
extension JSON: Equatable {}
JSON.swift:38
public func ==(lhs: JSON, rhs: JSON) -> Bool {
JSON.swift:38
public func ==(lhs: JSON, rhs: JSON) -> Bool {
JSON.swift:53
extension JSON: CustomStringConvertible, CustomDebugStringConvertible {
JSON.swift:79
extension JSON: IntegerLiteralConvertible, FloatLiteralConvertible, BooleanLiteralConvertible, NilLiteralConvertible {
JSON.swift:97
extension JSON: StringLiteralConvertible {
JSON.swift:111
extension JSON: ArrayLiteralConvertible, DictionaryLiteralConvertible {
JSON.swift:112
    public init(arrayLiteral elements: JSON...) {
JSON.swift:116
    public init(dictionaryLiteral elements: (Swift.String, JSON)...) {
JSONError.swift:84
        internal static func forValue(value: JSON) -> JSONType {
JSONError.swift:102
public extension JSON {
JSONError.swift:230
public extension JSON {
JSONError.swift:366
public extension JSON {
JSONError.swift:564
public extension JSON {
JSONError.swift:661
public extension JSON {
JSONError.swift:864
public extension JSON {
JSONError.swift:1237
public extension JSON {
JSONError.swift:1249
    static func map<T>(array: JSONArray, @noescape _ transform: JSON throws -> T) throws -> [T] {
JSONError.swift:1264
    static func flatMap<T>(array: JSONArray, @noescape _ transform: JSON throws -> T?) throws -> [T] {
JSONError.swift:1279
    static func flatMap<S: SequenceType>(array: JSONArray, _ transform: JSON throws -> S) throws -> [S.Generator.Element] {
JSONError.swift:1293
internal func getRequired(dict: JSONObject, key: String, type: JSONError.JSONType) throws -> JSON {
JSONError.swift:1298
internal func getRequired(ary: JSONArray, index: Int, type: JSONError.JSONType) throws -> JSON {
JSONObject.swift:26
    public init<S: SequenceType where S.Generator.Element == (String,JSON)>(_ seq: S) {
JSONObject.swift:35
    public private(set) var dictionary: [String: JSON]
JSONObject.swift:83
        private let base: Dictionary<String,JSON>.Index
JSONObject.swift:85
        private init(_ base: Dictionary<String,JSON>.Index) {
JSONObject.swift:98
        private var base: Dictionary<String,JSON>.Generator
JSONObject.swift:100
        private init(_ base: Dictionary<String,JSON>.Generator) {
JSONObject.swift:107
        public mutating func next() -> (String,JSON)? {
JSONObject.swift:125
    public var values: LazyMapCollection<JSONObject, JSON> {
JSONObject.swift:138
    public mutating func updateValue(value: JSON, forKey key: String) -> JSON? {
JSONObject.swift:138
    public mutating func updateValue(value: JSON, forKey key: String) -> JSON? {
JSONObject.swift:145
    public mutating func removeAtIndex(index: Index) -> (String,JSON)? {
JSONObject.swift:151
    public mutating func removeValueForKey(key: String) -> JSON? {
JSONObject.swift:163
    public mutating func popFirst() -> (String,JSON)? {
JSONObject.swift:170
    public init(_ dictionary: [String: JSON]) {
JSONObject.swift:175
    public init(dictionaryLiteral elements: (String, JSON)...) {
ObjectiveC.swift:19
    extension JSON {
ObjectiveC.swift:25
        public static func decode(data: NSData, strict: Swift.Bool = false) throws -> JSON {
ObjectiveC.swift:26
            return try JSON.decode(UTF8Decoder(data: data), strict: strict)
ObjectiveC.swift:33
        public static func encodeAsData(json: JSON, pretty: Swift.Bool = false) -> NSData {
ObjectiveC.swift:46
            JSON.encode(json, toStream: &output, pretty: pretty)
ObjectiveC.swift:51
    extension JSON {
ObjectiveC.swift:96
                var obj: [Swift.String: JSON] = Dictionary(minimumCapacity: dict.count)
ObjectiveC.swift:99
                    obj[key] = try JSON(ns: value)
ObjectiveC.swift:106
                    ary.append(try JSON(ns: elt))
{ 0017 /// The null value. 0018 case Null
Accessors.swift:19
        case .Null: return true
DecimalNumber.swift:63
            case .Null: return nil
Decoder.swift:71
        case .NullValue?: return .Null
Encoder.swift:36
        case .Null: encodeNull(&stream)
JSON.swift:40
    case (.Null, .Null): return true
JSON.swift:40
    case (.Null, .Null): return true
JSON.swift:56
        case .Null: return "null"
JSON.swift:68
        case .Null: return "JSON.Null"
JSON.swift:93
        self = .Null
JSONError.swift:86
            case .Null: return .Null
JSONError.swift:248
        case .Null: return nil
JSONError.swift:299
        case .Null:
JSONError.swift:359
        case .Null: return nil
ObjectiveC.swift:72
                self = .Null
ObjectiveC.swift:124
            case .Null: return NSNull()
ObjectiveC.swift:145
            case .Null: return nil
0019 /// A boolean. 0020 case Bool
Accessors.swift:27
        case .Bool: return true
Accessors.swift:85
        case .Bool(let b): return b
Decoder.swift:67
        case .BooleanValue(let b)?: return .Bool(b)
Encoder.swift:37
        case .Bool(let b): encodeBool(b, toStream: &stream)
JSON.swift:41
    case (.Bool(let a), .Bool(let b)): return a == b
JSON.swift:41
    case (.Bool(let a), .Bool(let b)): return a == b
JSON.swift:57
        case .Bool(let b): return Swift.String(b)
JSON.swift:69
        case .Bool(let b): return "JSON.Bool(\(b))"
JSON.swift:89
        self = .Bool(value)
JSONError.swift:87
            case .Bool: return .Bool
JSONError.swift:249
        case .Bool(let b): return Swift.String(b)
ObjectiveC.swift:64
                self = .Bool(true)
ObjectiveC.swift:67
                self = .Bool(false)
ObjectiveC.swift:125
            case .Bool(let b): return b as NSNumber
ObjectiveC.swift:146
            case .Bool(let b): return b as NSNumber
(Swift.Bool) 0021 /// A string. 0022 case String
Accessors.swift:35
        case .String: return true
Accessors.swift:93
        case .String(let s): return s
DecimalNumber.swift:30
            case .String(let s) where !s.isEmpty:
Decoder.swift:70
        case .StringValue(let s)?: return .String(s)
Encoder.swift:40
        case .String(let s): encodeString(s, toStream: &stream)
JSON.swift:42
    case (.String(let a), .String(let b)): return a == b
JSON.swift:42
    case (.String(let a), .String(let b)): return a == b
JSON.swift:58
        case .String(let s): return Swift.String(reflecting: s)
JSON.swift:70
        case .String(let s): return "JSON.String(\(Swift.String(reflecting: s)))"
JSON.swift:99
        self = .String(value)
JSON.swift:103
        self = .String(value)
JSON.swift:107
        self = .String(value)
JSONError.swift:88
            case .String: return .String
JSONError.swift:247
        case .String(let s): return s
JSONError.swift:290
        case .String(let s):
JSONError.swift:358
        case .String(let s): return Swift.Double(s)
ObjectiveC.swift:94
                self = .String(s)
ObjectiveC.swift:126
            case .String(let s): return s
ObjectiveC.swift:147
            case .String(let s): return s
(Swift.String) 0023 /// A 64-bit integer. 0024 case Int64
Accessors.swift:43
        case .Int64: return true
Accessors.swift:59
        case .Int64, .Double: return true
Accessors.swift:102
        case .Int64(let i): return i
Accessors.swift:121
        case .Int64(let i): return Swift.Double(i)
DecimalNumber.swift:28
            case .Int64(let i): return NSDecimalNumber(longLong: i)
DecimalNumber.swift:50
            case .Int64(let i): return NSDecimalNumber(longLong: i)
DecimalNumber.swift:61
            case .Int64(let i): return NSDecimalNumber(longLong: i)
Decoder.swift:68
        case .Int64Value(let i)?: return .Int64(i)
Encoder.swift:38
        case .Int64(let i): encodeInt64(i, toStream: &stream)
JSON.swift:43
    case (.Int64(let a), .Int64(let b)): return a == b
JSON.swift:43
    case (.Int64(let a), .Int64(let b)): return a == b
JSON.swift:45
    case (.Int64(let a), .Double(let b)): return Double(a) == b
JSON.swift:46
    case (.Double(let a), .Int64(let b)): return a == Double(b)
JSON.swift:59
        case .Int64(let i): return Swift.String(i)
JSON.swift:71
        case .Int64(let i): return "JSON.Int64(\(i))"
JSON.swift:81
        self = .Int64(value)
JSONError.swift:89
            case .Int64, .Double: return .Number
JSONError.swift:250
        case .Int64(let i): return Swift.String(i)
JSONError.swift:283
        case .Int64(let i):
JSONError.swift:356
        case .Int64(let i): return Swift.Double(i)
ObjectiveC.swift:83
                    self = .Int64(n.longLongValue)
ObjectiveC.swift:89
                    self = .Int64(Swift.Int64(val))
ObjectiveC.swift:127
            case .Int64(let i): return NSNumber(longLong: i)
ObjectiveC.swift:148
            case .Int64(let i): return NSNumber(longLong: i)
(Swift.Int64) 0025 /// A number. 0026 /// When decoding, any integer that doesn't fit in 64 bits and any floating-point number 0027 /// is decoded as a `Double`. 0028 case Double
Accessors.swift:51
        case .Double: return true
Accessors.swift:59
        case .Int64, .Double: return true
Accessors.swift:103
        case .Double(let d): return convertDoubleToInt64(d)
Accessors.swift:122
        case .Double(let d): return d
DecimalNumber.swift:29
            case .Double(let d): return NSDecimalNumber(double: d)
DecimalNumber.swift:51
            case .Double(let d): return NSDecimalNumber(double: d)
DecimalNumber.swift:62
            case .Double(let d): return NSDecimalNumber(double: d)
Decoder.swift:69
        case .DoubleValue(let d)?: return .Double(d)
Encoder.swift:39
        case .Double(let d): encodeDouble(d, toStream: &stream)
JSON.swift:44
    case (.Double(let a), .Double(let b)): return a == b
JSON.swift:44
    case (.Double(let a), .Double(let b)): return a == b
JSON.swift:45
    case (.Int64(let a), .Double(let b)): return Double(a) == b
JSON.swift:46
    case (.Double(let a), .Int64(let b)): return a == Double(b)
JSON.swift:60
        case .Double(let n): return Swift.String(n)
JSON.swift:72
        case .Double(let n): return "JSON.Double(\(n))"
JSON.swift:85
        self = .Double(value)
JSONError.swift:89
            case .Int64, .Double: return .Number
JSONError.swift:251
        case .Double(let d): return Swift.String(d)
JSONError.swift:285
        case .Double(let d):
JSONError.swift:357
        case .Double(let d): return d
ObjectiveC.swift:91
                    self = .Double(n.doubleValue)
ObjectiveC.swift:128
            case .Double(let d): return d
ObjectiveC.swift:149
            case .Double(let d): return d
(Swift.Double) 0029 /// An object. 0030 case Object
Accessors.swift:67
        case .Object: return true
Accessors.swift:130
        case .Object(let obj): return obj
Decoder.swift:84
            case .ObjectEnd: return .Object(JSONObject(dict))
Encoder.swift:41
        case .Object(let obj): encodeObject(obj, toStream: &stream, indent: indent)
JSON.swift:47
    case (.Object(let a), .Object(let b)): return a == b
JSON.swift:47
    case (.Object(let a), .Object(let b)): return a == b
JSON.swift:61
        case .Object(let obj): return Swift.String(obj)
JSON.swift:73
        case .Object(let obj): return "JSON.Object(\(Swift.String(reflecting: obj)))"
JSON.swift:117
        self = .Object(JSONObject(elements))
JSONError.swift:90
            case .Object: return .Object
ObjectiveC.swift:101
                self = .Object(JSONObject(obj))
ObjectiveC.swift:129
            case .Object(let obj): return obj.ns
ObjectiveC.swift:150
            case .Object(let obj): return obj.nsNoNull
(JSONObject) 0031 /// An array. 0032 case Array
Accessors.swift:75
        case .Array: return true
Accessors.swift:138
        case .Array(let ary): return ary
Decoder.swift:101
                return .Array(ary)
Encoder.swift:42
        case .Array(let ary): encodeArray(ary, toStream: &stream, indent: indent)
JSON.swift:48
    case (.Array(let a), .Array(let b)): return a == b
JSON.swift:48
    case (.Array(let a), .Array(let b)): return a == b
JSON.swift:62
        case .Array(let ary): return Swift.String(ary)
JSON.swift:74
        case .Array(let ary): return "JSON.Array(\(Swift.String(reflecting: ary)))"
JSON.swift:113
        self = .Array(JSONArray(elements))
JSONError.swift:91
            case .Array: return .Array
ObjectiveC.swift:108
                self = .Array(ary)
ObjectiveC.swift:130
            case .Array(let ary):
ObjectiveC.swift:151
            case .Array(let ary):
(JSONArray) 0033 } 0034 0035 public typealias JSONArray
Accessors.swift:136
    var array: JSONArray? {
Decoder.swift:98
        var ary: JSONArray = []
Encoder.swift:129
    private static func encodeArray<Target: OutputStreamType>(array: JSONArray, inout toStream stream: Target, indent: Int?) {
JSON.swift:32
    case Array(JSONArray)
JSON.swift:113
        self = .Array(JSONArray(elements))
JSONError.swift:215
    func getArray() throws -> JSONArray {
JSONError.swift:223
    func getArrayOrNil() throws -> JSONArray? {
JSONError.swift:524
    func getArray(key: Swift.String) throws -> JSONArray {
JSONError.swift:535
    func getArrayOrNil(key: Swift.String) throws -> JSONArray? {
JSONError.swift:545
    func getArray<T>(key: Swift.String, @noescape _ transform: JSONArray throws -> T) throws -> T {
JSONError.swift:557
    func getArrayOrNil<T>(key: Swift.String, @noescape _ transform: JSONArray throws -> T?) throws -> T? {
JSONError.swift:824
    func getArray(index: Int) throws -> JSONArray {
JSONError.swift:835
    func getArrayOrNil(index: Int) throws -> JSONArray? {
JSONError.swift:845
    func getArray<T>(index: Int, @noescape _ f: JSONArray throws -> T) throws -> T {
JSONError.swift:857
    func getArrayOrNil<T>(index: Int, @noescape _ f: JSONArray throws -> T?) throws -> T? {
JSONError.swift:1110
    func getArray(key: Swift.String) throws -> JSONArray {
JSONError.swift:1121
    func getArrayOrNil(key: Swift.String) throws -> JSONArray? {
JSONError.swift:1131
    func getArray<T>(key: Swift.String, @noescape _ f: JSONArray throws -> T) throws -> T {
JSONError.swift:1141
    func getArrayOrNil<T>(key: Swift.String, @noescape _ f: JSONArray throws -> T?) throws -> T? {
JSONError.swift:1249
    static func map<T>(array: JSONArray, @noescape _ transform: JSON throws -> T) throws -> [T] {
JSONError.swift:1264
    static func flatMap<T>(array: JSONArray, @noescape _ transform: JSON throws -> T?) throws -> [T] {
JSONError.swift:1279
    static func flatMap<S: SequenceType>(array: JSONArray, _ transform: JSON throws -> S) throws -> [S.Generator.Element] {
JSONError.swift:1298
internal func getRequired(ary: JSONArray, index: Int, type: JSONError.JSONType) throws -> JSON {
ObjectiveC.swift:103
                var ary: JSONArray = []
= ContiguousArray<JSON> 0036 0037 extension JSON: Equatable {} 0038 public func ==(lhs: JSON, rhs: JSON) -> Bool { 0039 switch (lhs, rhs) { 0040 case (.Null, .Null): return true 0041 case (.Bool(let a), .Bool(let b)): return a == b 0042 case (.String(let a), .String(let b)): return a == b 0043 case (.Int64(let a), .Int64(let b)): return a == b 0044 case (.Double(let a), .Double(let b)): return a == b 0045 case (.Int64(let a), .Double(let b)): return Double(a) == b 0046 case (.Double(let a), .Int64(let b)): return a == Double(b) 0047 case (.Object(let a), .Object(let b)): return a == b 0048 case (.Array(let a), .Array(let b)): return a == b 0049 default: return false 0050 } 0051 } 0052 0053 extension JSON: CustomStringConvertible, CustomDebugStringConvertible { 0054 public var description: Swift.String { 0055 switch self { 0056 case .Null: return "null" 0057 case .Bool(let b): return Swift.String(b) 0058 case .String(let s): return Swift.String(reflecting: s) 0059 case .Int64(let i): return Swift.String(i) 0060 case .Double(let n): return Swift.String(n) 0061 case .Object(let obj): return Swift.String(obj) 0062 case .Array(let ary): return Swift.String(ary) 0063 } 0064 } 0065 0066 public var debugDescription: Swift.String { 0067 switch self { 0068 case .Null: return "JSON.Null" 0069 case .Bool(let b): return "JSON.Bool(\(b))" 0070 case .String(let s): return "JSON.String(\(Swift.String(reflecting: s)))" 0071 case .Int64(let i): return "JSON.Int64(\(i))" 0072 case .Double(let n): return "JSON.Double(\(n))" 0073 case .Object(let obj): return "JSON.Object(\(Swift.String(reflecting: obj)))" 0074 case .Array(let ary): return "JSON.Array(\(Swift.String(reflecting: ary)))" 0075 } 0076 } 0077 } 0078 0079 extension JSON: IntegerLiteralConvertible, FloatLiteralConvertible, BooleanLiteralConvertible, NilLiteralConvertible { 0080 public init(integerLiteral value: Swift.Int64) { 0081 self = .Int64(value) 0082 } 0083 0084 public init(floatLiteral value: Swift.Double) { 0085 self = .Double(value) 0086 } 0087 0088 public init(booleanLiteral value: Swift.Bool) { 0089 self = .Bool(value) 0090 } 0091 0092 public init(nilLiteral: ()) { 0093 self = .Null 0094 } 0095 } 0096 0097 extension JSON: StringLiteralConvertible { 0098 public init(stringLiteral value: Swift.String) { 0099 self = .String(value) 0100 } 0101 0102 public init(extendedGraphemeClusterLiteral value: Swift.String) { 0103 self = .String(value) 0104 } 0105 0106 public init(unicodeScalarLiteral value: Swift.String) { 0107 self = .String(value) 0108 } 0109 } 0110 0111 extension JSON: ArrayLiteralConvertible, DictionaryLiteralConvertible { 0112 public init(arrayLiteral elements: JSON...) { 0113 self = .Array(JSONArray(elements)) 0114 } 0115 0116 public init(dictionaryLiteral elements: (Swift.String, JSON)...) { 0117 self = .Object(JSONObject(elements)) 0118 } 0119 } 0120