# How to flatten an object

**URL:** <https://community.thunkable.com/t/how-to-flatten-an-object/2036888>\
**Category:** Questions about Thunkable X\
**Created:** [September 11, 2022, 5:51pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888 "2022-09-11T17:51:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 11, 2022, 5:51pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/1 "2022-09-11T17:51:58Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 11, 2022, 6:00pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/2 "2022-09-11T18:00:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 11, 2022, 6:23pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/3 "2022-09-11T18:23:27Z")

</div>

See this output. is it what you are looking for?  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/c/0c72bd5b45a8e98a2316552cff819a4efab24d73.png)

Here is the code

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/0/d0f1d05ad95542edb48c7751b8294ee55777b530.png)

Have fun Thunking!

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 11, 2022, 6:53pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/4 "2022-09-11T18:53:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 11, 2022, 6:56pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/5 "2022-09-11T18:56:40Z")

</div>

> [@bibbi](#):
>
> it is no longer quite the starting point

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.

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 11, 2022, 7:02pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/6 "2022-09-11T19:02:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 11, 2022, 7:02pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/7 "2022-09-11T19:02:47Z")

</div>

See my new demo. I created 2 empty objects. One to hold the original JSON and one for the newly created JSON.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/0/80a2128c254673378cd1a205092ac350cb783843.png)

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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/4/449aaca8e77fe7c0d7c70d4abe06b5a312b30785.png)

This is a sample result  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/9/f912299daca4d50115102ea62e7ae413a611b524.png)

Hope this solves your issue.

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 11, 2022, 7:12pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/8 "2022-09-11T19:12:02Z")

</div>

hi

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

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 11, 2022, 8:14pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/9 "2022-09-11T20:14:27Z")

</div>

Thank you for your nice words.

Please mark it solved.

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 12, 2022, 4:27am UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/10 "2022-09-12T04:27:43Z")

</div>

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)

 ![Capture d’écran 2022-09-12 à 06.17.07](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/e/fe1324c3f5d9dfdcff28d244a44017136b0dfd37.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 12, 2022, 5:32am UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/11 "2022-09-12T05:32:17Z")

</div>

Does the list `tosheet` contains objects or JSON strings?

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 12, 2022, 5:37pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/12 "2022-09-12T17:37:47Z")

</div>

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’écran 2022-09-12 à 19.31.58](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/a/7ad5980cb3a775c80e53823f44fc7261bbf3b17e.png)

![Capture d’écran 2022-09-12 à 19.58.53](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/5/65dba135a2572d6381c061ba99c7d26526ebb63d.png)

a loop problem?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 12, 2022, 6:16pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/13 "2022-09-12T18:16:38Z")

</div>

I tried to make a similar loop but I do not see a problem  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/5/85560919ad14ca4fdb2974eb3b3774e5600fbf55.png)

Starting blocks  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/b/7b7e00eba4109124997239054b02c3ac0451fc58.png)

Main block

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/9/e9111fed24d2b508131c0c3e8d8f88b0cd0c298f.png)

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 12, 2022, 6:21pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/14 "2022-09-12T18:21:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 12, 2022, 6:28pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/15 "2022-09-12T18:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 12, 2022, 6:30pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/16 "2022-09-12T18:30:39Z")

</div>

> [@bibbi](#):
>
> get this variable which is not an app variable ?

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0fb25ae3cdc8f0caf7cd68197d4916a97b9b537f.png)

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

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 12, 2022, 6:37pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/17 "2022-09-12T18:37:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 12, 2022, 6:40pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/18 "2022-09-12T18:40:34Z")

</div>

> [@bibbi](#):
>
> it changes all “i” by the new name

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_.

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 12, 2022, 6:45pm UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/19 "2022-09-12T18:45:36Z")

</div>

Well I go back to my objects

thanks

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 13, 2022, 4:36am UTC](https://community.thunkable.com/t/how-to-flatten-an-object/2036888/20 "2022-09-13T04:36:22Z")

</div>

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🙂

[Next page](https://community.thunkable.com/t/how-to-flatten-an-object/2036888.md?page=2)
