How to flatten an object

hi

I am not a bypass champion.
and I could really use a hand flattening an object with thunkable
it looks like this

{“item”:“12”,“numitem”:1,“vkip”:“Day”,“vkipier”:“Eric”,“vdata”[0,0,1,5,0,10]}

and i would like to present it like this :

{“item”:“12”,“numitem”:1,“vkip”:“Day”,“vkipier”:“Eric”,“vd1”:0,"vd2:0,“vd3”:1,“vd4”:5,“vd6”:10}

is it possible ?

2 Likes

Can you say a little more about what you’re wanting Thunkable to do? Do you want to set up blocks to convert the first JSON to the second JSON?

1 Like

See this output. is it what you are looking for?
image

Here is the code

Have fun Thunking!

1 Like

hi

I should be happy for the support provided so efficient so fast
you have managed to extract the list but it is no longer quite the starting point or you think that I can do the rest

1 Like

I didn’t understand.

Do you want the full set to be shown?
You can loop through the object. Unfortunately, Thunkable does not have a block to delete/remove a key pair from an object.

Give me couple of minutes to de a demo.

hi

to tell you the truth, I was able to send objects one after the other in a spreadsheet but I wanted to send the json string (composed of several objects) at once and I did not find an accessible script to make it happen

Anyway, I’ll keep it off the list.

1 Like

See my new demo. I created 2 empty objects. One to hold the original JSON and one for the newly created JSON.
image

Now, I loop through the keys of the original JSON and test if the key is vdata. If yes then I loop through the content of this key, otherwise, I copy the key value pair as is.

This is a sample result
image

Hope this solves your issue.

1 Like

hi

I take a big hat off to you it’s perfect

thunkable can do it all i meant muneer can do it all

2 Likes

Thank you for your nice words.

Please mark it solved.

hi

with these blocks i try to flatten a list of ojbects saved in list tosheet but the loop loops when there is only one object in the list (I start small)

1 Like

Does the list tosheet contains objects or JSON strings?

1 Like

hi

I tried apart from your solution and I seem to be on the voice except that in tosheet I find the second element twice instead of having one and two

Capture d’écran 2022-09-12 à 19.58.53

a loop problem?

1 Like

I tried to make a similar loop but I do not see a problem
image

Starting blocks
image

Main block

I thought you could only nest two loops with variables i and j

1 Like

how do you do to get this variable which is not an app variable ?

1 Like

When you add a new loop block. click on the j or i variable, you will get a popup menu
image

Select Rename variable and choose a name for your loop variable.

when i do it
it changes all “i” by the new name
it doesn’t create a new one

1 Like

This is because you do copy/paste of the loop block.

You have to use a new block from the Control drawer. If you copy the block it will share the variable name and may create unexpected problems in the results.

This is an undocumented BUG.

1 Like

Well I go back to my objects

thanks

1 Like

hi

I know it’s borderline off topic but the list thus created is not considered as json
as json validator told me

then I transformed the list into a string Jason Jason validator said ok but when I parse in my script it no longer works (a very simple script to know who does what)

I should have just sent the objects one after the other🙂

1 Like