Parse PFCloud – “JSON text did not start with array or object”

It’s always the little things that lead to flatter foreheads (or at least it is for me).

Banging my head against the desk this evening working on a Parse migration, I finally figured out what was causing an error condition in a PFCloud function call.

The request to the server succeeded, but the response was malformed somehow:

Error Domain=NSCocoaErrorDomain Code=3840 “JSON text did not start with array or object and option to allow fragments not set.” UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

“What?? I know the response is supposed to be JSON – I can even test it out and it works great in Postman.”

Weeeelll, it turns out that if you don’t get the URL to your self-hosted Parse Server correct, you’re going to get a response that’s not JSON. Doh!

I had left off the “/parse” portion of the URL to my self-hosted parse server:

 1func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
 2    // Override point for customization after application launch.
 3    let configuration = ParseClientConfiguration {
 4        $0.applicationId = "YourAppId"
 5        $0.clientKey = "YourClientKey"
 6        $0.server = "https://your-self-hosted-parse-server/parse"
 7    }
 8    Parse.initializeWithConfiguration(configuration)
 9    
10    return true
11}

So, the bottom-line take-away? Make sure you get the full URL to your self-hosted Parse Server set to the server property of your ParseClientConfiguration instance. That endpoint could vary based on how you deployed the server to your cloud host of choice. For me, it was my goofy mistake of leaving off “/parse”.

Go forth and may your forehead be ever-more round than mine.

comments powered by Disqus