How to create nutrition app with ocr scanner?

When I connect it to my phone, it says that there is an error with the blocks. But when I try it on my computer the main label says “France, United States”. I want the nutrition score in the label not the countries.

APIs can be really tricky. If you want to provide the info I asked about, I can take another crack at it. It’s also really important that you identify which property you want from the actual JSON response. When you say “nutrition score,” there isn’t a property called that. So you need to look through the JSON and find a specific property name.

I found this property for the nutrition score

I still don’t know which property you mean.

Can you specify the property name/value pair? For example:

saturated_fat_value : 1.9

If you’re wanting all of the values under “nutriscore_data” (again, you have to be really exact when programming… it’s not enough to say you want the “nutrition score” or “nutrition” property because those don’t exist even though they may have those words within a property name*), that’s possible to do with lists but… I’d recommend keeping it really simple to start with and picking one property name to focus on.

*A property name is kind of like a password in the sense that if you leave out a character or use uppercase instead of lowercase, it won’t be recognized. It has to match the JSON response exactly.

1 Like

The “nutriscore_data” property has 32 sub-properties (hence the {32} after it). So while it’s technically possible to get the nutriscore_data, it’s not very useful because you have to then get each property from within it. In the screenshot above, the sub-property names are things like sugars_points, saturated_fat, saturated_fat_points, fiber_value, etc.

Those sub-properties are the ones you should choose from… for now.


I actually have to make this project for school and I need to include all the nutrition score and the nutrition grade in it. So how would I do that?

I can help you get a single property and then you can look over the documentation, tutorial videos, etc. to learn about the rest. Be aware that a property with square brackets [2] indicates a JSON array which is handled by list blocks in Thunkable.

And I mentioned this before but JSON/API data is difficult. Expect to spend several hours to figure this out, at least.

These blocks will give you the “transportation_score” property which currently has a value of 0 (zero).

Hopefully this will get you started!


Thank you!
For the nutrition score would I have to “initialize each app variable” for the nutritional information and then add it on the “get property of object” block?

Should it be something like this?

I decided to do only calories, saturated fat, sugars, salt, fiber, proteins, nuts, fruit and vegetables for the nutrition score, instead of doing all 32.

I shortened it a bit, and added the list. Is there anything I need to fix?

Can someone help me solve this or let me know what else I need to add? Sorry for sounding rude I just need to get this project finished very soon.

I just posted a tutorial that shows how to correctly parse JSON. I hope it’s helpful.

Thank you!

I looked at the tutorial, which was very helpful! I decided to use the property “nutriscore_grade”. I tried parsing the information like the video but I’m not sure if the blocks that I did are correct. Also I wasn’t sure what number to put in the get block.
This is the url I used:
Could you please let me know what I need to fix?

These are my blocks so far.

Thank you!

I’m glad it was helpful. The “nutriscore_grade” property is inside of the “product” property that’s inside of the object. So that’s it… just two of the “get property of object” blocks are needed for that value.

There are websites that will help you find the “path” to a JSON property. I don’t tend to use them but if you copy and paste your full JSON response text into, you can expand the “product” property and then click on “nutriscore_grade”. At the top will be the path:

It says “x.product.nutriscore_grade” and I’m assuming the “x” is the object in this case. So “product” is the first property and “nutriscore_grade” is the second. There’s nothing more than that so again, only two “get property of object” blocks are needed to get that value instead of the 7 blocks in your screenshot.


Okay! Thank you so much!
I fixed that but when I try to test it, there is just a blank white screen that shows up.
These are my blocks:

Is it possible that your product doesn’t have that property? What barcode number are you testing it with?

This works fine for me (returning the value “e”), using the url that you provided earlier,

You’re also not checking the green “error” block for the barcode scanner. That’s a recipe for disaster!

I’m not sure how to check the green “error” box. Could you explain me how to check it?