Select out the main objects from a json file

Hi!
I have a following json file from a web url:

{“place1”:{“wert1”:270,“wert2”:310,“wert3”:10},“place2”:{“wert1”:89,“wert2”:109,“wert3”:30}}

I want to select the main objects like place1 and place2. It can be more than two. So it should work dynamic.
Hope somebody can help how I can do this.

Here my example:
json_get
But this doesn’t work.

Hope somebody can help me.
kindly regards

You can’t set the text items to j because each item in the list is another JSON object.

What are you wanting to display in the list viewer? Which values from the API result?

Do you just want it to look like this?

Place1
Place2
Place3

1 Like

Thanks for the answer.
Yes I want display in the list viewer as result
Place1
Place2
Place3

Later I want all further details wert1, wert2,… from place1 when I select it in the list viewer.
kindly regards

I’m not sure what you posted above is valid JSON. I tried a bunch of JSON validators online and they all returned errors. Can you copy the entire result from the web and paste it here? Are you using a third-party API or your own server?

1 Like

Thanks again for your answer.
Here the copy from the webserver:

{“place1”:{“wert1”:270,“wert2”:310,“wert3”:10},“place2”:{“wert1”:89,“wert2”:109,“wert3”:30}}

I will get now a valid code. I think the double quoutes were wrong.
I use my server from my provider.
kindly regards

Edit: just saw your response. Yep, it was the quotes.

I honestly think it might be the smart quotes that are messing things up. Because I constructed a JSON string using the same data and it looks identical except for the quotes… and it is valid JSON:

{“place1”:{“wert1”:270,“wert2”:310,“wert3”:10},“place2”:{“wert1”:89,“wert2”:109,“wert3”:30}}

Hmm… I’ve never created my own JSON so I’m struggling a little bit here. But I think you’ve attempted to create a JSON array but without brackets [ ]. I’m not sure how to fix it but I’m trying a few different formats to see what might work.

Try this

{
  "All": {
    "Places1": {
      "Wert1": 89,
      "Wert2": 21,
      "Wert3": 43
    },
    "Places2": {
      "Wert1": [12,34,64],
      "Wert2": ["care with this apostrophes","sheesh"],
      "Wert3": "text in apostrophes"
    }
  }
}

I don’t know if the apostrophes are correct or not here. I’m making this on my phone.

1 Like

Okay, this worked (it took a ridiculous amount of time for me to figure out!):

{“Places”:[{“name”:“Place1”,“wert1”:270,“wert2”:310,“wert3”:10},{“name”:“Place2”,“wert1”:89,“wert2”:109,“wert3”:30}]}

If you paste that into the left side of the page at https://jsonformatter-online.com, you’ll see the format on the right side:

And these blocks retrieve the name and “wert1” value of the first set:

But wait, there’s more!!!

To populate the list viewer, loop through the Places like this:

And to get the “wert1” value of the list item that is clicked:

2 Likes

Just a couple of weeks ago, I discovered that the ARRAY (aka List) in JSON was a later addition to JSON (5. Arrays, Objects, Functions and JSON - Mixu's Node book). Using Properties with names like place1,place2, place3, etc. feels a bit peculiar for me, who learned JSON through Thunkable.

To loop through properties which are treated like a list, you can use the following loop structure:



https://x.thunkable.com/copy/fe54663300fc58722be1a778daa55fe2

Notice the loop is through the PROPERTIES of the object, not the object itself (like when the object is an array (as in tatiang’s example). Then if you want to get the object, you need to use the Get Object Property Block.

It feels a bit pecular, but it has some advantages. One big advantage is that you can reference objects in a list by NAME, rather than having to loop through the list to find it. One big disadvantage is that the order is dependent on the object name.

2 Likes