Need help with JSON list and API (Bug?)

I’m building this app based on the API of Jisho, it is a dictionary for Japanese symbols. The code is very simple. I have the link https://jisho.org/api/v1/search/words?keyword= then after the equal sign, I add a word and it will give me all of the results that include that word, in JSON format. For example. if I type “now” who’s japanese symbol is, “今”, it will give me results of the word “now” (今), but also all other words that use the symbol “now,” like the word “today.” (今日). What I want to do is go into the data, then from the list “japanese” I want to get the “word” object. What I am trying right now is what I just mentioned. Everything should work fine. I have included labels that are changed when I click the button, to see if the “word” variable and the api link are joined correctly, and if it works correctly, it will also change the text in the label in the japanese symbol of the word Inputted. (So if I inputted “now,” it will change the label to 今). When I run the app on the web viewer, the link and the variable “word” are correctly joined, however, I get no response on the second label, and in less than a second, the app crashes. I then tried it on my Android phone running Android 10, (the latest update) and in there the link and the variable are not joined, and for the second label I get response “undefined.” I tried it on an iOS device running iOS 13.4.1, (the latest), and I get the same situation as the web viewer, where the link and the variable are properly joined, but I get no response on the second label and the app crashes. Any idea what I should do? I think my blocks are correct, and I have tried inputting the japanese characters as a label, so Thunkable should support them. Either way they are just unicode. Here are the pictures of my code:

1 Like

If I understand your question correctly, you are having problems getting JSON nodes. To solve this problem, you need to correctly create the path to the desired node. How do I do this?

I recommend that everyone use the online service https://jsonpath.com/, which can be used to quickly find the right path.

Try this line:

$. data.[0].japanese.[1]. reading

[] is a list.

After that, you need to implement this path in blocks:

  1. get the data node
  2. get the first item in the list
  3. get a Japanese node
  4. get the second item in the list
  5. get the reading node

Any other paths are created in the same way

2 Likes

Hey @22morales5827tqbl2t

I created a sample app for you: https://x.thunkable.com/copy/a290693b266dfa12282eaea7b1a46980

It is key to understand that:

  • you are dealing with two arrays, the first one is under “data” and the second one is under “japanese”.
  • the first element in JSON objects is 0 while in lists is 1, hence my subtraction of 1 from the lists items count.

There is no error checking which explains the two “undefined” results when searching for “morning”.

Oh… and my example returns all entries, not just the first one so go ahead and remix my project as needed :smiley:

I hope this helps :slight_smile:

Konstantinos

3 Likes

This is cool! Nice job! I was having a hard time with this api. for the last two days, I was getting a failure to fetch.

my blocks dont look different, so now it’s time to try again…