I am trying to create a scripture trivia game that generates a random scripture reference and pulls the text for that scripture from an API. I have it working for a reference that includes one or two verses, but I am running into problems once I get to three or more verses. It seems like I am getting the first and last, but nothing in the middle.
Here is the json response
"q": "Isaiah 58:6-8",
"scripture": "Isaiah 58:6",
"text": "Is not this the fast that I have chosen? to loose the bands of wickedness, to undo the heavy burdens, and to let the oppressed go free, and that ye break every yoke?"
"scripture": "Isaiah 58:7",
"text": "Is it not to deal thy bread to the hungry, and that thou bring the poor that are cast out to thy house? when thou seest the naked, that thou cover him; and that thou hide not thyself from thine own flesh?"
"scripture": "Isaiah 58:8",
"text": "Then shall thy light break forth as the morning, and thine health shall spring forth speedily: and thy righteousness shall go before thee; the glory of the LORD shall be thy rereward."
Here is my block where I’m storing the data in a string variable
Here is an alternate block where I store the data in a list (with the same issue)
Here is an image of an app result (not the same scripture obviously, but the same principle applies) in case the context is helpful.
Are you using an API to get the data? Can you share the project? I might be able to help if you still need it
Yes, I’m getting all of the data from the API (api.nephi.org). I’m new to the platform and hesitant to share the project, but I did include a screen shot of the code that is exhibiting the weird behavior, should be fairly quick to reproduce it!
This problem is with the API response, not with your JSON parsing blocks. Read on…
Your API is returning only some verses. So when you should be getting verses 40-42, the API is only returning 40 & 42, not 41:
There is nothing wrong with your blocks or with Thunkable. I suspect this might be the cause from the API’s website:
Books, chapters and verses that don’t exist will simply not be included, no errors or empty placeholders are shown.
I can see why you thought the first and last verses were the only ones working. But if you do more extensive testing of your project, you’ll notice that some single verses (e.g. Psalm 119:105) do not display at all and some that should have two or more verses only display one (e.g. Doctrine & Covenants 76:22-24). The missing data is not included in the API response.
You can check this by adding a Text Input component and setting its text value to the green response block. Then, when you click Reveal Answer, copy the Text Input’s text from Thunkable Live. Paste it into Best JSON Viewer and JSON Beautifier Online to format it in a viewable tree.
Edit: I think actually that the API does return the full set of verses most of the time. But something about the url you are using to call the API doesn’t return a full set of verses. I’m not sure why yet!
You’re using a long hyphen aka “dash” (–) between verse numbers when calling the API. But you need to use a regular hyphen (-) instead.
For example, if you go to https://api.nephi.org and search for this:
2 Timothy 3:15-17
You’ll get back verses 15, 16 and 17.
But if you search for this:
2 Timothy 3:15–17
You’ll only get back verses 15 and 17.
missing verse? John 8:43 had the answer: https://api.nephi.org/scriptures/?q=John+8%3A43
@manyone Wow! Nicely done.
Thanks! Also I realized I had left the ‘s’ off in “Psalms” so that explains why that single verse wasn’t working as well.