             return scanner.scanString("null", into: nil) ? .null : nil
         }
 
-        func lineNumber(location: Int) -> Int {
-            let string = scanner.string as NSString
-            let subString = string.substring(to: location)
-            return subString.characters.filter({ $0 == "\n" }).count
-        }
-
         var tokens = [Token]()
+        var tokenLocations = [TokenLocation]()
+        func appendToken(_ token: Token) {
+            tokens.append(token)
+            tokenLocations.append(TokenLocation(scanner.scanLocation))
+        }
         while !scanner.isAtEnd {
             let previousScanLocation = scanner.scanLocation
-            scanBeginObject().flatMap({ tokens.append($0) })
-            scanEndObject().flatMap({ tokens.append($0) })
-            scanBeginArray().flatMap({ tokens.append($0) })
-            scanEndArray().flatMap({ tokens.append($0) })
-            scanColon().flatMap({ tokens.append($0) })
-            scanComma().flatMap({ tokens.append($0) })
-            scanBool().flatMap({ tokens.append($0) })
-            scanNumber().flatMap({ tokens.append($0) })
-            scanString().flatMap({ tokens.append($0) })
-            scanNull().flatMap({ tokens.append($0) })
+            scanBeginObject().flatMap({ appendToken($0) })
+            scanEndObject().flatMap({ appendToken($0) })
+            scanBeginArray().flatMap({ appendToken($0) })
+            scanEndArray().flatMap({ appendToken($0) })
+            scanColon().flatMap({ appendToken($0) })
+            scanComma().flatMap({ appendToken($0) })
+            scanBool().flatMap({ appendToken($0) })
+            scanNumber().flatMap({ appendToken($0) })
+            scanString().flatMap({ appendToken($0) })
+            scanNull().flatMap({ appendToken($0) })
             let currentScanLocation = scanner.scanLocation
             guard currentScanLocation > previousScanLocation else {
-                print("Not found valid token at line: \(lineNumber(location: currentScanLocation))")
+                print("Not found valid token: [\(lineNumber(of: currentScanLocation))]")
                 break
             }
         }
-        return tokens
+        return (tokens, tokenLocations)
     }
 
     private func parse() -> Value? {
 
-        let tokens = generateTokens()
+        let (tokens, tokenLocations) = generateTokens()
         guard !tokens.isEmpty else {
             print("No tokens")
             return nil

                next += 1
            }
            guard let token = tokens[coolie_safe: next] else {
                print("No token for parseString")
                return nil
            }
            if case .string(let string) = token {

                            return .array(name: name, values: array)
                        } else {
                            guard let _ = parseComma() else {
                                print("Expect comma: [\(lineNumber(of: tokenLocations[next].location))]")
                                break
                            }
                            guard let nextToken = tokens[coolie_safe: next], nextToken.isNotEndArray else {
                                print("Invalid JSON, comma at end of array: [\(lineNumber(of: tokenLocations[next].location))]")
                                break
                            }
                        }
