Dictionary search by tags - JSON

Hi,
I have the following JSON data structure:

{
  "animals": [
    {
      "spec": "dog",
      "name": "Fargus",
      "desc": "agressive",
      "age": 12,
      "tags": [
        "home",
        "outside",
        "fat"
      ]
    },
    {
      "spec": "cat",
      "name": "Bubus",
      "desc": "gentle",
      "age": 7,
      "tags": [
        "home",
        "fat"
      ]
    },
    {
      "spec": "cat",
      "name": "Lusia",
      "desc": "gentle",
      "age": 6,
      "tags": [
        "home",
        "outside"
      ]
    }
  ]
}

I would like to get a list that shows all the values of the names if there is a value of "fat" in the list key "tags".
I've tried doing this with the JsonPath extension and also with dictionary structures, but I can't get the desired results.
How could I do it best?
Please help and thank you in advance for your reply!

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

I closed your question on the Kodular community. Only ask on the community of the builder you use.

You may not have designed dictionary blocks properly

You can easily get it by desingning like this. (Here i am showing you the tags list whose is containing the name fat

This is the easiest and simplest way i think..

1 Like

Thank you very much!
But this is first step of my problem...
I would like to get a list of key "name" values ​​for all objects with the "fat" Tag. So I don't know how to get to the list: (Fargus, Bubus)...

1 Like

So simple. Here i am taking the name as well the age

image

2 Likes

Thank you very much for solution!
Best regards
OH

1 Like

With DecoJson extension

.animals[?(@.tags[-1]=='fat')].name

borrar_jsonextension.aia (582.0 KB)

2 Likes

thank you! it's working :slight_smile:
I don't fully understand the syntax of JsonPath.
I'm having a hard time building accurate queries, even though I've reviewed several tutorials.

Is there any way to turn the result into a list?
Label1 shows the result as if it were a list, but if I put the JsonPath result into a variable and try to set as ListView elements I get an error....

@Oskar_Hamerski1

I have modified the extension a bit, before we got ["Fargus","Bubus"], now we get the string "Fargus","Bubus" which we can easily convert into a list.
You can download the updated extension from...
http://kio4.com/appinventor/299G_extension_Decodifica_Json.htm

p299G_DecodificaJson_nombre.aia (582.4 KB)

2 Likes

Great! It works fantastic :slight_smile:

I noticed that if the result of the query does not produce any outcome e.g. when using "&&" operators in the query, then it does not return an empty list, but returns the error "Cannot parse text argument to "list from csv row" as CSV-formatted row". Do you know how this can be fixed?

I handled it this way:

@Oskar_Hamerski

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.