Simple Frustating JSON

Hello,
Can someone help, how to get the value of this JSON response?
I cannot use index position, since the position is not always the same.

So, using the { “attribute_key” : “value” } is the best.
My question is, how to filter specific key/value pair, and get the “value” in same JSON child.

For example, if I need to get value of “long_v”, which is the value for “temperature”.
I cannot figure this out

{

    "attribute_kv": [

        {

            "attribute_key": "temperature",

            "long_v": 30,

            "dbl_v": null

        },

        {

            "attribute_key": "cloudCover",

            "long_v": 19,

            "dbl_v": null

        },

        {

            "attribute_key": "solarDNI",

            "long_v": null,

            "dbl_v": 178.23

        },

        {

            "attribute_key": "inactivityTimeout",

            "long_v": 600000,

            "dbl_v": null

        },

        {

            "attribute_key": "refresh_api",

            "long_v": null,

            "dbl_v": null

        },

        {

            "attribute_key": "inv_qty",

            "long_v": 3,

            "dbl_v": null

        },

        {

            "attribute_key": "total_capacity",

            "long_v": 3,

            "dbl_v": null

        },

        {

            "attribute_key": "solarDHI",

            "long_v": null,

            "dbl_v": 65.05

        },

        {

            "attribute_key": "weatherCode",

            "long_v": 1100,

            "dbl_v": null

        },

        {

            "attribute_key": "solarGHI",

            "long_v": null,

            "dbl_v": 149.12

        },

        {

            "attribute_key": "active",

            "long_v": null,

            "dbl_v": null

        },

        {

            "attribute_key": "lastDisconnectTime",

            "long_v": 0,

            "dbl_v": null

        },

        {

            "attribute_key": "lastConnectTime",

            "long_v": 0,

            "dbl_v": null

        },

        {

            "attribute_key": "lastInactivityAlarmTime",

            "long_v": 1628075359929,

            "dbl_v": null

        },

        {

            "attribute_key": "pv_inv_ratio",

            "long_v": null,

            "dbl_v": 1.2

        },

        {

            "attribute_key": "lastActivityTime",

            "long_v": 1628074741182,

            "dbl_v": null

        },

        {

            "attribute_key": "lat",

            "long_v": null,

            "dbl_v": -6.224007000203784

        },

        {

            "attribute_key": "lon",

            "long_v": null,

            "dbl_v": 106.6603225304693

        }

    ]

}
1 Like

Attribute_kv is a list and all the rest values are entries in the list.

I created this sample project from your JSON.

Have a look

https://x.thunkable.com/projectPage/610a981f8204ae0283e417a8

1 Like

Hi Muneer,
Thank you very much for the help. I did successfully make list output based on your example.
But, what if I need to display specific value on the “label”.

1 Like

I changed the project and added another List Viewer which only shows the attribute_key. When you select any item in the list the other two keys long_v, dbl_v are displayed in the labels under the list.

Just remix the project to get the changes.

1 Like

Hi Muneer,
I have try to modify your example to query specific parts of JSON only without success.
I can easily do this with JSONata attribute_kv[attribute_key=‘temperature’].long_v , but it won’t work on Thunkable.

Would you please help me to make an example?
Not to show them on list, but on single label.

So, for example, I just want to query “long_v” value with “attribute_key : temperature”, and show the value on label, instead list.

Many thanks for your help, I’ve been trying to solve this out for 3 days without success. :slight_smile:

1 Like

The JSON you have is a List of Objects and there isn’t an easy way in thunkable to get the values.

If the list is a normal list of entries then you will use


But this will not work because each entry in the list is actually a JSON object therefore, you will need to loop through all the entries and check if it is the one you want. using this
image

I have changed in the project to include the test using the loop that creates the 2 lists. You can remix to see it and of course, you can remove the blocks that creates the lists from the loop if all what you want to do is to display this single value.

Perfect… It works.
Thank you very much for the time you’ve spent on this. I greatly appreciate it.

1 Like