# Error decoding parse-server response

**URL:** <https://community.parseplatform.org/t/error-decoding-parse-server-response/1446>\
**Category:** ParseSwift SDK\
**Created:** [March 14, 2021, 1:23pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446 "2021-03-14T13:23:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![claesjacobsson](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@claesjacobsson](https://community.parseplatform.org/u/claesjacobsson)\
**Post date:** [March 14, 2021, 1:23pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/1 "2021-03-14T13:23:36Z")

</div>

I’m playing around with ParseSwift and a local Parse Server (4.5.0). Whenever I try to perform a query or saving an object to the server I get the error below. Not sure what I’m doing wrong…

```
ParseError code=-1 error=Error decoding parse-server response: Optional(<NSHTTPURLResponse: 0x600003071700> { URL: http://0.0.0.0:4040//classes/Link } { Status Code: 404, Headers {
    Connection = (
        "keep-alive"
    );
    "Content-Length" = (
        153
    );
    "Content-Security-Policy" = (
        "default-src 'none'"
    );
    "Content-Type" = (
        "text/html; charset=utf-8"
    );
    Date = (
        "Sun, 14 Mar 2021 13:20:46 GMT"
    );
    "Keep-Alive" = (
        "timeout=5"
    );
    "X-Content-Type-Options" = (
        nosniff
    );
    "X-Powered-By" = (
        Express
    );
} }) with error: The data couldn’t be read because it isn’t in the correct format.

```

My Link object:

```
struct Link: ParseObject {
        var objectId: String?
        var createdAt: Date?
        var updatedAt: Date?
        var ACL: ParseACL?
        var title: String?
    }

```

This is my query:

```
func myQuery() {
        let query = Link.query()
        query.find(callbackQueue: .main) { results in
            switch results {
            case .success(let links):
                links.forEach { link in
                    print("Found link: \(link)")
                }
                
            case .failure(let error):
                print("Error: \(error.localizedDescription)")
            }
        }
    }
```

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 1:28pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/2 "2021-03-14T13:28:57Z")

</div>

Can you share some sample code along with the ParseObject you are trying to save/query? We would need to see your `Link` ParseObject and any ParseObjects it embeds.

Also, do you see errors on the server when saving/querying your object?

---

<div class="post-metadata">

**Author:** ![claesjacobsson](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@claesjacobsson](https://community.parseplatform.org/u/claesjacobsson)\
**Post date:** [March 14, 2021, 2:10pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/3 "2021-03-14T14:10:49Z")

</div>

Sorry, my bad. Embarrassed to admit I was calling the Dashboard URL instead of the Server API endpoint. Thanks for trying to help!

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 8:58pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/4 "2021-03-14T20:58:06Z")

</div>

Well I’m getting the same error trying to User.login() to my Back4app server:

` Error logging in: ParseError(code: ParseSwift.ParseError.Code.unknownError, message: "Error decoding parse-server response: Optional(<NSHTTPURLResponse: 0x6000016612c0> { URL: https://parseapi.back4app.com/login } { Status Code: 200, Headers {\n \"Access-Control-Allow-Origin\" = (\n \"*\"\n );\n \"Content-Encoding\" = (\n gzip\n );\n \"Content-Length\" = (\n 221\n );\n \"Content-Type\" = (\n \"application/json; charset=utf-8\"\n );\n Date = (\n \"Sun, 14 Mar 2021 20:50:02 GMT\"\n );\n Etag = (\n \"W/\\\"12b-pwtHiE5t80haWPqUXfiYEXYWIzo\\\"\"\n );\n Server = (\n nginx\n );\n Vary = (\n \"Accept-Encoding\"\n );\n Via = (\n \"1.1 eae631604d5db564451a93106939a61e.cloudfront.net (CloudFront)\"\n );\n \"access-control-allow-credentials\" = (\n true\n );\n \"access-control-allow-headers\" = (\n \"DNT, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, X-Application-ID, X-Access-Token, X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, X-CSRF-Token, X-Parse-Client-Key\"\n );\n \"access-control-allow-methods\" = (\n \"GET, POST, PUT, PATCH, DELETE, OPTIONS\"\n );\n \"access-control-expose-headers\" = (\n \"X-Parse-Job-Status-Id, X-Parse-Push-Status-Id\"\n );\n \"x-amz-cf-id\" = (\n \"ZfKitwBPt93JbhN5v2FYrdbdoQSfI3-zjCEf4kTL5CF-SG5wtKhGmQ==\"\n );\n \"x-amz-cf-pop\" = (\n \"YUL62-C1\"\n );\n \"x-cache\" = (\n \"Miss from cloudfront\"\n );\n \"x-content-type-options\" = (\n nosniff\n );\n \"x-frame-options\" = (\n SAMEORIGIN\n );\n \"x-powered-by\" = (\n Express\n );\n \"x-xss-protection\" = (\n \"1; mode=block\"\n );\n} }) with error: The data couldn’t be read because it isn’t in the correct format.")`

I double checked that I am not using the dashboard URL 😊 By the details, it returns HTTP 200, which means non error.

I’ve been able to save an Installation record (without login in). Updating it fails with the same error 😕

I tried version 4.2 and version 4.4.0 of the server to no avail. Hints?

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 9:20pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/5 "2021-03-14T21:20:29Z")

</div>

Can you share the code for your `User` ParseObject and any ParseObjects it embeds. Also, can you share how you are logging in?

When testing, you should connect your Swift Playground code (3 and 4 are relevant to your issue):

> **[parse-community/Parse-Swift](https://github.com/parse-community/Parse-Swift/tree/main/ParseSwift.playground/Pages)**
>
> main/ParseSwift.playground/Pages

You can set the settings for your server in here:

> <https://github.com/parse-community/Parse-Swift/blob/main/ParseSwift.playground/Sources/Common.swift>

If the playgrounds work with your server, then you most likely have something wrong in your `User` struct or your code and should compare it to the ones in Playgrounds.

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 9:33pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/6 "2021-03-14T21:33:17Z")

</div>

I’ve initialized it properly since the Install data got written.

Here’s my User struct:

```auto
struct PKUser: ParseUser {
    //: These are required for `ParseObject`.
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?

    //: These are required for `ParseUser`.
    var username: String?
    var email: String?
    var password: String?
    var authData: [String: [String: String]?]?
}

```

I’m digging into the Parse-Swift code. The server response data is:

```auto
{
  "objectId": "siQS1p3rUw",
  "emailVerified": true,
  "username": "plbeaudoin",
  "createdAt": "2021-03-14T02:24:47.841Z",
  "updatedAt": "2021-03-14T02:24:52.417Z",
  "email": "pierre-luc@pierlux.com",
  "ACL": {
    "*": {
      "read": true
    },
    "siQS1p3rUw": {
      "read": true,
      "write": true
    }
  },
  "sessionToken": "r:REDACTED"
}

```

and the JSONDecode error is:

```auto
typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "createdAt", intValue: nil)], debugDescription: "Expected to decode Dictionary<String, Any> but found a string/data instead.", underlyingError: nil))

```

I’m still trying to understand the error 😁

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 9:38pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/7 "2021-03-14T21:38:00Z")

</div>

The server response looks fine. What version of Parse-Swift are you using?

Did the SDK give you that decoder error, or did you decode that with something else?

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 9:49pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/8 "2021-03-14T21:49:48Z")

</div>

I’m using ParseSwift (1.1.6) (from Cocopods).

I’ve gotten this decoding error message by adding a do {} catch {} around line 197 in ParseUser.swift. Without it, I only get the error in my first message in this thread.

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 9:54pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/9 "2021-03-14T21:54:27Z")

</div>

Parse dates have a particular date strategy that needs to be set on the encoder/decoder, so you shouldn’t use your own. Instead, try something `User().getDecoder().decode(...)` if you are debugging.

I recommend setting a breakpoint at line 197 as you mentioned. In the console log winder type `po try ParseCoding.jsonDecoder().decode(AnyCodable.self, from: data)` and post your output. It should look similar to your server response above, but something seems weird about the dates.

Then try the original line, `po try ParseCoding.jsonDecoder().decode(LoginSignupResponse.self, from: data)`. Does it give you an error? It may be the next line that’s giving you and issue when it attempts to decode as your user type. Try, `po try ParseCoding.jsonDecoder().decode(Self.self, from: data)`

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 9:58pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/10 "2021-03-14T21:58:01Z")

</div>

In addition, try the playgrounds method I mentioned because if it works, we can rule out the SDK and the Server, leaving the issue to your implementation.

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 10:05pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/11 "2021-03-14T22:05:59Z")

</div>

Here we go:

> [@cbaker6](#):
>
> `po try ParseCoding.jsonDecoder().decode(AnyCodable.self, from: data)`

```auto
(lldb) po try ParseCoding.jsonDecoder().decode(AnyCodable.self, from: data)
▿ AnyCodable(["ACL": ["*": ["read": true], "siQS1p3rUw": ["read": true, "write": true]], "updatedAt": "2021-03-14T02:24:52.417Z", "createdAt": "2021-03-14T02:24:47.841Z", "emailVerified": true, "email": "pierre-luc@pierlux.com", "sessionToken": "r:REDACTED", "objectId": "siQS1p3rUw", "username": "plbeaudoin"])
  - dateEncodingStrategy : nil
  ▿ value : 8 elements
    ▿ 0 : 2 elements
      - key : "ACL"
      ▿ value : 2 elements
        ▿ 0 : 2 elements
          - key : "*"
          ▿ value : 1 element
            ▿ 0 : 2 elements
              - key : "read"
              - value : true
        ▿ 1 : 2 elements
          - key : "siQS1p3rUw"
          ▿ value : 2 elements
            ▿ 0 : 2 elements
              - key : "read"
              - value : true
            ▿ 1 : 2 elements
              - key : "write"
              - value : true
    ▿ 1 : 2 elements
      - key : "updatedAt"
      - value : "2021-03-14T02:24:52.417Z"
    ▿ 2 : 2 elements
      - key : "createdAt"
      - value : "2021-03-14T02:24:47.841Z"
    ▿ 3 : 2 elements
      - key : "emailVerified"
      - value : true
    ▿ 4 : 2 elements
      - key : "email"
      - value : "pierre-luc@pierlux.com"
    ▿ 5 : 2 elements
      - key : "sessionToken"
      - value : "r:228369aec37a5b09560df3931cb8b0b7"
    ▿ 6 : 2 elements
      - key : "objectId"
      - value : "siQS1p3rUw"
    ▿ 7 : 2 elements
      - key : "username"
      - value : "plbeaudoin"

```

Where

```auto
po try ParseCoding.jsonDecoder().decode(LoginSignupResponse.self, from: data)

```

gives me the error I got by adding the do/catch around line 197:

```auto
▿ DecodingError
  ▿ typeMismatch : 2 elements
    - .0 : Swift.Dictionary<Swift.String, Any>
    ▿ .1 : Context
      ▿ codingPath : 1 element
        - 0 : CodingKeys(stringValue: "createdAt", intValue: nil)
      - debugDescription : "Expected to decode Dictionary<String, Any> but found a string/data instead."
      - underlyingError : nil

```

I’ll look into starting the docker server.

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 10:09pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/12 "2021-03-14T22:09:35Z")

</div>

Actually, something is wrong with the way the server is dishing the date. It should look like:

```auto
{\"sessionToken\":\"myToken\",\"username\":\"hello10\",\"objectId\":\"yarr\",\"updatedAt\":{\" __type\":\"Date\",\"iso\":\"2021-03-14T18:04:20.485Z\"},\"email\":\"hello@parse.com\",\"createdAt\":{\"__ type\":\"Date\",\"iso\":\"2021-03-14T18:04:20.485Z\"},\"customKey\":\"blah\"

```

Your date doesn’t have the `iso` info. At that same breakpoint can you post the output for `po String(data: data, encoding: .utf8)`?

@davimacedo does the back4app server do anything particular with dates? The Parse-Swift SDK is expecting to see `\"__type\":\"Date\",\"iso\":\"2021-03-14T18:04:20.485Z\"`

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 10:13pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/13 "2021-03-14T22:13:50Z")

</div>

Indeed the dates are not Dictionary\<String, Any\> but String/data instead!

```auto
"createdAt": "2021-03-14T02:24:47.841Z",
"updatedAt": "2021-03-14T02:24:52.417Z",

```

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 10:16pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/14 "2021-03-14T22:16:20Z")

</div>

Yup, the standard Parse Server dishes dates which look like: `\"createdAt\":{\"__type\":\"Date\",\"iso\":\"2021-03-14T18:04:20.485Z\"` which is what ParseSwift is expecting to decode.

Lets wait for @davimacedo he probably knows why this is happening and how to fix it. I suspect it’s a setting on the server side.

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 10:28pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/15 "2021-03-14T22:28:24Z")

</div>

@pierlux Can you post the full output from `po String(data: data, encoding: .utf8)` at the breakpoint?

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 10:30pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/16 "2021-03-14T22:30:35Z")

</div>

Sure:

```auto
po String(data: data, encoding: .utf8)
▿ Optional<String>
  - some : "{\"objectId\":\"siQS1p3rUw\",\"emailVerified\":true,\"username\":\"plbeaudoin\",\"createdAt\":\"2021-03-14T02:24:47.841Z\",\"updatedAt\":\"2021-03-14T02:24:52.417Z\",\"email\":\"pierre-luc@pierlux.com\",\"ACL\":{\"*\":{\"read\":true},\"siQS1p3rUw\":{\"read\":true,\"write\":true}},\"sessionToken\":\"r:REDACTED\"}"

```

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 10:41pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/17 "2021-03-14T22:41:50Z")

</div>

Just some more info on what ParseSwift expects to see, it uses the REST API (if you see something in your back4app settings that says “enable for REST”, “use REST endpoints”, or something similar, that may help). Here is the documentation that talks about the date for REST in Parse Server [REST API Guide | Parse](https://docs.parseplatform.org/rest/guide/#data-types)

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 10:59pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/18 "2021-03-14T22:59:02Z")

</div>

Can you set a breakpoint here and let me know what happens. It should still be able to parse the `String` unless there’s something up with the format

> <https://github.com/parse-community/Parse-Swift/blob/0b0d775e404dc6affbb017f271d6469d365f8853/Sources/ParseSwift/Coding/ParseCoding.swift#L69>

---

<div class="post-metadata">

**Author:** ![pierlux](https://community.parseplatform.org/user_avatar/community.parseplatform.org/pierlux/32/532_2.png) [@pierlux](https://community.parseplatform.org/u/pierlux)\
**Post date:** [March 14, 2021, 11:22pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/19 "2021-03-14T23:22:13Z")

</div>

Sure.

```auto
decodedString = "2021-03-14T02:24:47.841Z"	

```

but then the dateFormatter chokes on it and it trows on line 74.

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [March 14, 2021, 11:39pm UTC](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446/20 "2021-03-14T23:39:45Z")

</div>

> [@pierlux](#):
>
> `2021-03-14T02:24:47.841Z`

Update: decoding the string date should still work. I added a test here:

> <https://github.com/parse-community/Parse-Swift/blob/a80705accaf0513799afd4eafef89c288c08c485/Tests/ParseSwiftTests/ParseEncoderTests.swift#L96-L103>

Something is up with that particular day/time. When I use the date string you give me it fails (just like you are getting). If I switch the day or year by 1, it passes.

Maybe it has something to do with daylight savings time where I’m at? (this doesn’t make sense to me), but I’m not sure what the problem could be. Maybe something with the timezone or needing to be set to something like UTC.

[Next page](https://community.parseplatform.org/t/error-decoding-parse-server-response/1446.md?page=2)
