What is causing a SyntaxError with an unexpected token B in JSON while creating a Notion database item from a Google Sheet row?

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.

@U04T6B6HMC6 My workflow includes a Google sheets trigger and a notion step. I am not writing any code so I cannot provide the JSON

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 i get more help than this? I have the same flow working with another notion database but for some reason this one is getting an error

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.

Cheers! Unfortunately there is nothing under the Exports section, it is greyed out

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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?

all data being passed through are strings and I am using the paths provided by the previous trigger

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.

1 Like

groovy let me see where i get with that, cheers

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.

e.g. we expect an object but you’re passing a string