简体   繁体   中英

"Unexpected token } in JSON" (Firestore connecting through Zapier)

Attempting to hook up a trigger from Zapier when a Firestore document gets added, Zapier asks for an orderBy element. Documentation ( https://zapier.com/help/firebase/#creating-a-firestore-structured-query-for-a-trigger ) seems pretty straightforward, but I get an error that

ERROR: We had trouble finding a sample. The specified query does not contain valid JSON. Unexpected token } in JSON at position 123

I tried a couple of variations (see below for 2 examples), but I keep getting the same error each with a different position. 在此处输入图像描述 "orderBy": [{ "field": { "fieldPath": "timestamp" }, "direction": "DESCENDING" }], (Result: Position 123)

"orderBy": [{
  "field": "timestamp,
  "direction": "DESCENDING"
}],
(Result: Position 46)

I'm not even sure where Zapier is getting the JSON, so I can't look at the JSON to see if anything is funky.

Does anyone know how to fix, or at least how to view the full JSON file?

问题是最后一个[ ]后面的逗号,这使它成为无效的JSON。

Actually it's this one trailing comma, which renders the query invalid: ]},} - that should be ]}} .

The full JSON can usually be downloaded in the Firebase console; at least for Realtime Database.

And when it complains about JSON syntax, just use JSONLint ; most IDE also highlight syntax errors.

According to Zapier documentation:

"orderBy": [{
        "field": {
            "fieldPath": "someKeyOfYourChoice"
        },
        "direction": "DESCENDING"
    }]

This worked for me. There are more cases of troubleshooting, I highly suggest to check the site out if you still experiencing some issues: https://zapier.com/help/doc/common-problems-firebase#creating-a-firestore-structured-query-for-a-trigger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM