               }
             }
             """
-        XCTAssertEqual(json.sorted(), expected.sorted())
+        XCTAssertEqual(
+            json.components(separatedBy: .whitespacesAndNewlines).joined().sorted(),
+            expected.components(separatedBy: .whitespacesAndNewlines).joined().sorted()
+        )
     }
     
     func testEncodeAdditionalProperties() {

              }
            }
            """
        XCTAssertEqual(json.sorted(), expected.sorted())
    }
    
    func testEncodeOptionalEmpty() {

    // Note: When encoding a JSON object to a string, Mac and Linux produce different key orderings.
    // This is valid, since there is no required order for the keys in a Swift Dictionary or JSON object.
    // However, the different key orderings make it difficult to compare the strings for equality.
    // The `prettyPrinted` option also uses varying amounts of whitespace on Mac and Linux.
    // Instead of directly comparing strings for equality, we strip all whitespace then sort the
    // resulting strings, to ensure that they contain the same characters.

    static var allTests = [
        ("testEncodeNil", testEncodeNil),
