How to create nutrition app with ocr scanner?

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?

If the “error” block has a value, you generally shouldn’t proceed with the next steps because it will likely result in the app crashing or other unpredictable behavior.

In the tutorial video I made, I show how to use an if/then block to check that value.

But a simple way to check it is to assign the “error” block to a label’s text and see what the result is.


This is what it says in the error box:

Ohhh… you should live test it on your device

Okay thank you it worked on my phone! But when the barcode scanner opens on my phone, it goes onto a different camera but doesn’t let me take a picture or scan anything.

Yes it does. When you pass the camera over a barcode it automatically captures the barcode.

1 Like

Okay I’ll try again

I’m trying to get the nutriscore so I put in the positive and negative points but when I scan it just says “undefined”.