# Key-value pairs as exposed state?

**URL:** <https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643>\
**Category:** Plugin builders\
**Created:** [March 24, 2019, 7:00am UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643 "2019-03-24T07:00:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [March 24, 2019, 7:00am UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/1 "2019-03-24T07:00:52Z")

</div>

Is it possible to expose a state that’s a list/collection of key-value pairs? I’m thinking along the lines of a simple flat JS object with property names and values which the Bubble programmer would access like a “thing” - e.g. “exposed state’s prop1’s value” or some such.

Nothing in the plugin builder or docs seems to suggest this is possible, but I want to make sure I’m not missing something.

These key/value pairs would not be configured in the property editor, but rather generated internally within the plugin.

Any ideas?

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [April 16, 2019, 5:45pm UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/2 "2019-04-16T17:45:49Z")

</div>

I feel like I’m missing something here. There must be a way to expose a series of named values, no?

---

<div class="post-metadata">

**Author:** ![zelus\_pudding](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/zelus_pudding/32/68250_2.png) [@zelus\_pudding](https://forum.bubble.io/u/zelus_pudding)\
**Post date:** [June 15, 2022, 3:33pm UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/3 "2022-06-15T15:33:01Z")

</div>

Unfortunately, I do not believe this is possible even here in 2022. Of course, you can always expose a string of text that is JSON, but actually defining named keys that you can work with in the editor is a no go ☹ Wish it was.

Would really like to see the ability to define an array of keys for visual elements. This is possible for Plugin actions but not for visual elements 😢 Or am I wrong @cal ?

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [June 15, 2022, 5:06pm UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/4 "2022-06-15T17:06:31Z")

</div>

> [@zelus\_pudding](#):
>
> I do not believe this is possible even here in 2022.

Strictly speaking, that is true AFAIK. However, a couple solutions have come to light in the 3+ years since this thread was started.

- If there are a known limited number of keys, then a [custom Bubble type](http://forum.bubble.io/t/output-an-object-for-server-side-client-side/59419) (that’s not tied to the DB) can be defined. This results in the best Bubble developer experience. I’ve used this approach in published plug-ins.

- If the key names or number of key/value pairs can vary, a simple “cheater” approach is to publish a list of delimited strings as an exposed state (the 2nd option [described here](http://forum.bubble.io/t/output-an-object-for-server-side-client-side/59419/90)). It makes use of the `:split by` operator (which wasn’t available at the time this thread was created). It’s super simple and flexible, but it’s not the most elegant approach if you plan to distribute the plugin.

---

<div class="post-metadata">

**Author:** ![dannyliu](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/dannyliu/32/123904_2.png) [@dannyliu](https://forum.bubble.io/u/dannyliu)\
**Post date:** [June 15, 2022, 8:26pm UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/5 "2022-06-15T20:26:46Z")

</div>

> [@sudsy](#):
>
> I’m thinking along the lines of a simple flat JS object with property names and values which the Bubble programmer would access like a “thing” - e.g. “exposed state’s prop1’s value” or some such.
> 
> Nothing in the plugin builder or docs seems to suggest this is possible, but I want to make sure I’m not missing something.
> 
> These key/value pairs would not be configured in the property editor, but rather generated internally within the plugin.
> 
> Any ideas?

ah I’ve always solved this problem by importing the JSON as a string into bubble and then JSON.parse() it into a JS object. Every key-value pair is available from there.

Some JS is needed to take each item’s key-value pair and save it onto a custom state, which can then be transferred to the bubble database.

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [June 15, 2022, 9:18pm UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/6 "2022-06-15T21:18:52Z")

</div>

> [@dannyliu](#):
>
> Some JS is needed to take each item’s key-value pair and save it onto a custom state,

Yes, I’ve seen that technique mentioned elsewhere. However, I’m a bit of a “purist” and don’t like “polluting” my Bubble environment with JS. The only JS in my apps resides inside plug-ins; but that’s just my personal philosophy. 🙂

---

<div class="post-metadata">

**Author:** ![zelus\_pudding](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/zelus_pudding/32/68250_2.png) [@zelus\_pudding](https://forum.bubble.io/u/zelus_pudding)\
**Post date:** [June 16, 2022, 3:59pm UTC](https://forum.bubble.io/t/key-value-pairs-as-exposed-state/52643/7 "2022-06-16T15:59:54Z")

</div>

Unfortunately the intention was to make a distributable plugin 😢

Does seem a bit odd that plugin actions offer this but visual elements do not.
