This topic was automatically generated from Slack. You can find the original thread here.
hola again I am creating a notion database item from a row in a google sheet. i have another flow that is currently active and working, i thought i set this one up the same however i am getting the following error: SyntaxError
Unexpected token B in JSON at position 0
hola again I am creating a notion database item from a row in a google sheet. i have another flow that is currently active and working, i thought i set this one up the same however i am getting the following error: SyntaxError
Unexpected token B in JSON at position 0
Iâm sorry to hear that youâre experiencing an issue with your flow. The error youâre encountering, âUnexpected token B in JSON at position 0â, typically occurs when the code is trying to parse a non-JSON string as JSON. To help you further, Iâll need more information about your flow, specifically the part where youâre parsing the JSON. Can you please share the relevant code snippet or the step in your flow where this error occurs? This will help me identify the issue and provide a solution.
I understand that youâre using a Google Sheets trigger and a Notion step in your workflow without any custom code. In this case, itâs possible that the error is related to the data being passed between the steps or the configuration of the steps themselves. To help you further, can you please provide more details about the Google Sheets trigger and the Notion step youâre using? For example, which specific Notion action are you using, and what are the input values youâre providing to that action? This information will help me identify the issue and suggest a solution.
Can you show me a screenshot of the configuration for the Notion action? Iâd like to see exactly how data is being passed to that step. It has nothing to do with whether youâre writing code, or not â weâre trying to parse the data you raised, and it might not be a valid JavaScript object / JSON passed from another step. So Iâd like to see exactly whatâs being passed.
If youâre referencing data from prior steps, it would help to see a screenshot of the Exports section below the step to see the format the data is in. That way I can trace from the original data â this Notion step, and see how the code is interpreting that data. Thatâll help me troubleshoot more.
hey just following up to see if any guidance was available. Iâm just perplexed because i set up a very similar workflow that did not have this error. cheers
Iâm not sure on this one. Itâs likely related to the data youâre passing to that step in one of the params â Iâd recommend inspecting each param to see exactly what data youâre passing. I asked ChatGPT about the error and it provided a helpful response:
The error message âUnexpected token B in JSON at position 0â indicates that there is a problem with the JSON (JavaScript Object Notation) data you are trying to parse or work with. The error suggests that the parser encountered an unexpected character, âBâ, at the beginning of the JSON string (position 0). Here are a few things you can check to resolve this error:
Validate the JSON: Make sure that the JSON data is properly formatted. JSON data must start with either a curly brace { for an object or a square bracket [ for an array. If it starts with âBâ, itâs not valid JSON.
Encoding Issue: Sometimes, data fetched from an external source can contain a Byte Order Mark (BOM) or other unexpected characters. Make sure that the JSON data is encoded in UTF-8 without BOM.
Content Type: If youâre receiving the JSON from a server or an API, ensure that the content type is set to application/json. Sometimes, a response might be mistakenly identified as JSON when it is not.
Check for Errors: If youâre receiving the JSON from a server, check that the server isnât returning an error message instead of JSON data. Sometimes, error messages are sent as plain text or HTML, and the first letter of the error message might be the âBâ that the JSON parser is complaining about.
Debugging: Log the data that youâre trying to parse as JSON to the console or any other output before parsing it. This can help you identify if thereâs something unexpected in the data.
Parsing Code: If youâre manually parsing JSON in your code (e.g., using JSON.parse() in JavaScript), double-check the code to make sure it is correct.
By checking these aspects, you should be able to identify and fix the issue causing the âUnexpected token B in JSON at position 0" error.
thank you for the info. how would i adjust the json code behind these steps? Are you saying I should check the data being passed from the google sheet to the notion database?
On any fields that are JSON objects, e.g. { "a": 3 }, can you convert the expression youâre passing in to convert that string to an actual JavaScript object? e.g.
{{steps.test.$return_value.property}}
should be converted to:
{{JSON.parse(steps.test.$return_value.property)}}
You only need to do this for fields that are JSON objects. If youâre just passing a normal string, like "test", or a number like 3, you donât need to JSON.parse the data. Only if the data youâre passing to that step is an object.
Or since youâre seeing Unexpected token B in JSON at position 0, look for any data youâre passing from the previous step where the value begins with the letter âBâ. We may be trying to treat a specific field as JSON in the code, but if youâre passing just a string, itâll throw this error.