JSON help for dictionary

Hi!

The app I’m making involves using a dictionary api, but I’m unsure of what JSON blocks to use in order to get the value definition from this JSON. Could someone please help me with the blocks required?
[ { "word": "hello", "phonetics": [ { "text": "/həˈloʊ/", "audio": "https://lex-audio.useremarkable.com/mp3/hello_us_1_rr.mp3" }, { "text": "/hɛˈloʊ/", "audio": "https://lex-audio.useremarkable.com/mp3/hello_us_2_rr.mp3" } ], "meanings": [ { "partOfSpeech": "exclamation", "definitions": [ { "definition": "Used as a greeting or to begin a phone conversation.", "example": "hello there, Katie!" } ] }, { "partOfSpeech": "noun", "definitions": [ { "definition": "An utterance of “hello”; a greeting.", "example": "she was getting polite nods and hellos from people", "synonyms": [ "greeting", "welcome", "salutation", "saluting", "hailing", "address", "hello", "hallo" ] } ] }, { "partOfSpeech": "intransitive verb", "definitions": [ { "definition": "Say or shout “hello”; greet someone.", "example": "I pressed the phone button and helloed" } ] } ] } ]
Formatted:
[
{
“word”: “hello”,
“phonetics”: [
{
“text”: “/həˈloʊ/”,
“audio”: “https://lex-audio.useremarkable.com/mp3/hello_us_1_rr.mp3
},
{
“text”: “/hɛˈloʊ/”,
“audio”: “https://lex-audio.useremarkable.com/mp3/hello_us_2_rr.mp3
}
],
“meanings”: [
{
“partOfSpeech”: “exclamation”,
“definitions”: [
{
“definition”: “Used as a greeting or to begin a phone conversation.”,
“example”: “hello there, Katie!”
}
]
},
{
“partOfSpeech”: “noun”,
“definitions”: [
{
“definition”: “An utterance of “hello”; a greeting.”,
“example”: “she was getting polite nods and hellos from people”,
“synonyms”: [
“greeting”,
“welcome”,
“salutation”,
“saluting”,
“hailing”,
“address”,
“hello”,
“hallo”
]
}
]
},
{
“partOfSpeech”: “intransitive verb”,
“definitions”: [
{
“definition”: “Say or shout “hello”; greet someone.”,
“example”: “I pressed the phone button and helloed”
}
]
}
]
}
]

I never expected these blocks to work, but please suggest how I may change them;


Thanks!
cc: @drted

1 Like

First, import/rebuild the JSON Formatter Function to get a better sense for how the data is organized. That should help you see how all of the nested levels are organized.

Next import/rebuild the JSON Dictionary Functions (no relation to this dictionary). That way you won’t have to use nested get property blocks.

Alternatively, you could set a cloud variable to the response and use firebase to figure out the levels then use cloud variables to get the elements you need.

1 Like

To bounce off of Ted, I would recommend checking out this website. Are use this whenever I am using a new Json because it makes figuring out the format super easy

2 Likes

Can you post the entire JSON response? It looks like you left part of it out.

Also, I think you’re close but the “definitions” section is an array so you’ll need to get the first list item of “definitions” as well.

1 Like

I’ve used jsonformatter-online.com to sort out the data (@tatiang introduced me). No, The data came just like that, starting with the square brackets. @drted, could you please share a screenshot of the blocks that would help with firebase? Also, you could copy this into jsonformatter-online.com. While it’s significantly much better than the plain JSON, it’s still confusing for a beginner like me.
Thanks!

1 Like

So I would have to use this?


I’ve tried it but it’s returning undefined. I think I’ve skipped a couple of properties. If it’s not too much trouble, could you share a screenshot of the blocks I would require?
Thanks!

1 Like

Yes, that’s what I was suggesting.

Okay, I see now that it’s from the Google Dictionary API (https://dictionaryapi.dev).

It’s returning an array so the first block has to get the first list item of the response.

Use these blocks:

3 Likes

Thank you very much for your help! My question my have seemed silly, but JSON was and is not one of my strong points.
Thanks again to all of you!

1 Like

Since there are sometimes more than one definition for a word, is it possible to display them all in a list viewer? I’m also showing part of speech, and synonyms. How do I make it so that I can display all of them together, for each definition of the word?
Thanks

You’d have to create a list by looping through the get property of object “definitions” blocks and taking their “definition” property. Then, assign that list to a listviewer’s text items.

I’m thinking of cloning the columns so that all the definitions and related information are visible for each definition of the word. I’ve got many labels, like Definition, Pronunciation, etc. How do I differentiate between each label clone? How do I name their current clone to set the text?
I’ve tried this:



Thanks!

I think you’ll want something like this:

1 Like