Skip to content

Commit

Permalink
Output no unneeded whitespace in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Obbut committed Sep 2, 2016
1 parent be503fd commit 26c0d2d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions Sources/ExtendedJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@ extension Value {
case .binary(let subtype, let data):
let base64 = Data(bytes: data).base64EncodedString()
let subtype = String(subtype.rawValue, radix: 16).uppercased()
return "{\"$binary\": \"\(base64)\", \"$type\": \"0x\(subtype)\"}"
return "{\"$binary\":\"\(base64)\",\"$type\":\"0x\(subtype)\"}"
case .objectId(let id):
return "{\"$oid\": \"\(id.hexString)\"}"
return "{\"$oid\":\"\(id.hexString)\"}"
case .boolean(let val):
return val ? "true" : "false"
case .dateTime(let date):
let dateString = isoDateFormatter.string(from: date)
return "{\"$date\": \"\(dateString)\"}"
return "{\"$date\":\"\(dateString)\"}"
case .null:
return "null"
case .regularExpression(let pattern, let options):
return "{\"$regex\": \"\(escape(pattern))\", \"$options\": \"\(escape(options))\"}"
return "{\"$regex\":\"\(escape(pattern))\",\"$options\":\"\(escape(options))\"}"
case .javascriptCode(let code):
return "{\"$code\": \"\(escape(code))\"}"
return "{\"$code\":\"\(escape(code))\"}"
case .javascriptCodeWithScope(let code, let scope):
return "{\"$code\": \"\(escape(code))\", \"$scope\": \(scope.makeExtendedJSON())}"
return "{\"$code\":\"\(escape(code))\",\"$scope\":\(scope.makeExtendedJSON())}"
case .int32(let val):
return String(val)
case .timestamp(let t, let i):
return "{\"$timestamp\": {\"t\": \(t), \"i\": \(i)}}"
return "{\"$timestamp\":{\"t\":\(t),\"i\":\(i)}}"
case .int64(let val):
return "{\"$numberLong\": \"\(val)\"}"
return "{\"$numberLong\":\"\(val)\"}"
case .minKey:
return "{\"$minKey\": 1}"
return "{\"$minKey\":1}"
case .maxKey:
return "{\"$maxKey\": 1}"
return "{\"$maxKey\":1}"
case .nothing:
return "{\"$undefined\": true}"
return "{\"$undefined\":true}"
}
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ extension Document {
}.reduce("[") { "\($0),\($1)" } + "]"
} else {
str = self.makeIterator().map { pair in
return "\"\(pair.key)\": \(pair.value.makeExtendedJSON())"
return "\"\(pair.key)\":\(pair.value.makeExtendedJSON())"
}.reduce("{") { "\($0),\($1)" } + "}"
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/BSONTests/BSONPublicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class BSONPublicTests: XCTestCase {

func testExtendedJSON() throws {

let simpleJson = "{\"kaas\": 4.2}"
let simpleJson = "{\"kaas\": 4.2}"
let simpleDocument = try Document(extendedJSON: simpleJson)
XCTAssertEqual(simpleDocument["kaas"], ~4.2)

Expand All @@ -337,7 +337,7 @@ class BSONPublicTests: XCTestCase {

XCTAssertEqual(kittenDocument, otherDocument)

XCTAssertEqual(Value.nothing.makeExtendedJSON(), "{\"$undefined\": true}")
XCTAssertEqual(Value.nothing.makeExtendedJSON(), "{\"$undefined\":true}")
}

func testDocumentIndexes() {
Expand Down

0 comments on commit 26c0d2d

Please sign in to comment.