Syntax error - Unexpected end of JSON input

Hey guys, I am almost embarrassed to be asking this as it seems like a really rookie mistake which I just can’t seem to get my finger on.

I have got 2 different workflows where I call the ChatGPT plugin’s chat completion API. Both call 2 different system content (prompt). But on both, I do take in a variable called birthChartValues which is essentially,

return JSON.stringify(context.workflow['c20f746d-04e6-4168-aad5-9e850518e7e0'].result?.['data']);

On the first workflow, it works well and as expected. It completes the call and returns a result. But on the 2nd workflow, which is a slightly longer system prompt, with another set of JSON data passed as a variable alongside the birthChartValues as with the first, but somehow I keep getting a “SyntaxError: Unexpected end of JSON input”.

When I troubleshoot, it seems like the birthChartValues is the culprit kicking up the error. But it is the same code and value used on the first prompt which executes as expected. What am I doing wrong? Here is the string representation for clarity sake,

"{"0":{"name":"Ascendant","isRetro":"false","fullDegree":149.1347617406815,"normDegree":29.134761740681512,"current_sign":5,"current_house":1,"nakshatra":12,"nakshatraName":"Uttara Phalguni","pada":1,"nakshatraLord":"Sun","raasi":5,"raasiName":"Leo","raasiLord":"Sun"},"1":{"name":"Sun","isRetro":"false","fullDegree":105.2313265126479,"normDegree":15.231326512647897,"current_sign":4,"current_house":12,"nakshatra":8,"nakshatraName":"Pushya","pada":4,"nakshatraLord":"Saturn","raasi":4,"raasiName":"Cancer","raasiLord":"Moon"},"2":{"name":"Moon","isRetro":"false","fullDegree":49.022449161234064,"normDegree":19.022449161234064,"current_sign":2,"current_house":10,"nakshatra":4,"nakshatraName":"Rohini","pada":3,"nakshatraLord":"Moon","raasi":2,"raasiName":"Taurus","raasiLord":"Venus"},"3":{"name":"Mars","isRetro":"false","fullDegree":192.97624839292757,"normDegree":12.976248392927573,"current_sign":7,"current_house":3,"nakshatra":15,"nakshatraName":"Swati","pada":2,"nakshatraLord":"Rahu","raasi":7,"raasiName":"Libra","raasiLord":"Venus"},"4":{"name":"Mercury","isRetro":"false","fullDegree":85.89158751354667,"normDegree":25.891587513546668,"current_sign":3,"current_house":11,"nakshatra":7,"nakshatraName":"Punarvasu","pada":2,"nakshatraLord":"Jupiter","raasi":3,"raasiName":"Gemini","raasiLord":"Mercury"},"5":{"name":"Jupiter","isRetro":"false","fullDegree":110.55164611844332,"normDegree":20.551646118443315,"current_sign":4,"current_house":12,"nakshatra":9,"nakshatraName":"Ashlesha","pada":2,"nakshatraLord":"Mercury","raasi":4,"raasiName":"Cancer","raasiLord":"Moon"},"6":{"name":"Venus","isRetro":"false","fullDegree":139.59610136361096,"normDegree":19.596101363610956,"current_sign":5,"current_house":1,"nakshatra":11,"nakshatraName":"Purva Phalguni","pada":2,"nakshatraLord":"Venus","raasi":5,"raasiName":"Leo","raasiLord":"Sun"},"7":{"name":"Saturn","isRetro":"true","fullDegree":348.98997165794555,"normDegree":18.989971657945546,"current_sign":12,"current_house":8,"nakshatra":27,"nakshatraName":"Revati","pada":1,"nakshatraLord":"Mercury","raasi":12,"raasiName":"Pisces","raasiLord":"Jupiter"},"8":{"name":"Rahu","isRetro":"true","fullDegree":8.66593251950356,"normDegree":8.66593251950356,"current_sign":1,"current_house":9,"nakshatra":1,"nakshatraName":"Ashwini","pada":3,"nakshatraLord":"Ketu","raasi":1,"raasiName":"Aries","raasiLord":"Mars"},"9":{"name":"Ketu","isRetro":"true","fullDegree":188.66593251950357,"normDegree":8.66593251950357,"current_sign":7,"current_house":3,"nakshatra":15,"nakshatraName":"Swati","pada":1,"nakshatraLord":"Rahu","raasi":7,"raasiName":"Libra","raasiLord":"Venus"},"10":{"name":"Uranus","isRetro":"false","fullDegree":148.61055593430228,"normDegree":28.610555934302283,"current_sign":5,"current_house":1,"nakshatra":12,"nakshatraName":"Uttara Phalguni","pada":1,"nakshatraLord":"Sun","raasi":5,"raasiName":"Leo","raasiLord":"Sun"},"11":{"name":"Neptune","isRetro":"true","fullDegree":208.18690017950513,"normDegree":28.18690017950513,"current_sign":7,"current_house":3,"nakshatra":16,"nakshatraName":"Vishakha","pada":3,"nakshatraLord":"Jupiter","raasi":7,"raasiName":"Libra","raasiLord":"Venus"},"12":{"name":"Pluto","isRetro":"false","fullDegree":145.58003748109581,"normDegree":25.580037481095815,"current_sign":5,"current_house":1,"nakshatra":11,"nakshatraName":"Purva Phalguni","pada":4,"nakshatraLord":"Venus","raasi":5,"raasiName":"Leo","raasiLord":"Sun"}}"

Any help is appreciated. I can’t believe I am stuck on such a trivial bug. Thanks in advance!

Hi, could you provide the formula you’re using ?

Is this JSON you pasted the result of a JSON.stringify or the raw format you have ?

Hey, thanks for reaching out. It seems like the syntax error was a little misleading, and I had exceeded the token limit which was causing this. While I have you here, is there any good practices that I can implement to catch these kinda errors? Primary reason was because I do pass in a set of JSON data which could vary in size as an input to the chat completion. Can’t believe it took me 3 days just to zero in on what was potentially causing this. arghh

It depends, this error was a response from openai API right ? At first I though you had the syntax error inside our formula input.

My question is, was the “SyntaxError: Unexpected end of JSON input” an API error response or a weweb error caused by an unexpected response from the API (because of the token limit)

If you know how to use the network tab of your browser dev tools you should be able to see the exact response and see if there is a human readable error message like “token limit exceeded” or not.

If so, you should be able to attach an on error workflow and display a warning for example. :thinking: