Thunkable unable to recognize JSON received from API

This is my first question here, so sorry if there is anything wrong with my post.
I’m making a project using both Thunkable and Python. I have made a web server using the python library Flask and I am using Thunkable as my front end. So in my code, I make a request to my site:

And my server side code is:

image

So I am able to connect with my server and receive data from it, but for some reason, my thunkable program cannot recognize it is JSON and hence errors out during the ‘create object from JSON’ part.

I have tested and I have received the data, but I don’t know why thunkable is erroring out. Any suggestions?

1 Like

Could you please post the JSON that isn’t working? Put the server response in a label temporarily, or have the python log exactly what it’s sending?

Or just do that get request in a browser window?

1 Like

From the server side everything is going fine. I’m just using some test data for now, like {TEST : “test”} or something like that. Also, if I directly display the received data in a label, it shows up properly. So I think the problem is Thunkable does not recognize it as a JSON.

1 Like

You’re missing your quotes on TEST. This works:

If your server is actually returning what you posted, that’s your problem - badly formatted JSON.

1 Like

Ah sry, that was a typo. In reality it was

image

so if you paste exactly what the server is returning into the test blocks above, does it work? If so, it’s a web server problem. If not, it’s a web_api problem.

I suggest displaying labels with the server response, status, and error while testing. You might learn something.

1 Like

There is nothing wrong. Response shows the text I gave, status shows 200 and error shows undefined.

Another thing, it seems the error is on this line

image

1 Like

That pink block will definitely cause a crash if you’re asking for a property that doesn’t exist in your object.

2 Likes

Does TEST not exist? {“TEST”:“LMFAO”}?

I agree that it should. And when I set a variable to those values, it works fine. So what blocks are above the small screenshot you posted? Show me where you set the variable “name”? And show me the label with the unprocessed server response? Or PM me a link to the server or to the project so I can see it myself, if you like?

1 Like


I’m just printing it to a label I already had set up

image

1 Like

your last picture doesn’t show the server response?

No it does, it is just what it looks like before it.
Just change the code to
image
And it should print there

I can’t run your code. Even if I wanted to recreate it all out from the screenshots, I can’t actually see the full URL you’re using in that join block, so there’s no way I can recreate it here.

1 Like

The url is https://SpottedPureAnimatronics.ismailatrepl.repl.co/loginl

1 Like

Another thing, I don’t know why, but if I list out all the all the properties it gives me an infinite list starting from 0 like [0,1,2,3,4,5] etc…

1 Like

I remixed your project. Thunkable is getting ‘null’ for response when I try it, although when I paste the URL into a browser I get the text you listed. I also tried with curl, and I see the server sending a 200 status, so I’m not sure why that’s not getting through Thunkable either.

I wonder if you need to get the server to send a different content type? Can you get it to report a content-type of application/json instead of text/html ? I’m not sure this is the problem, but it’s my best guess.

2 Likes

When you get a response from the server it will most probably be in JSON format. Thunkable sees JSON as formatted text and cannot work with it.

To use the get property block first convert the JSON to object then use the object blocks. Use get object from JSON for Thunkable to treat at as an object.

2 Likes

You can see an example of how to use the get object from JSON block at the 17:49 mark in my tutorial video:

2 Likes