# How do I Stringify an object in Bubble?

**URL:** <https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612>\
**Category:** Plugin builders\
**Created:** [January 26, 2023, 7:23pm UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612 "2023-01-26T19:23:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin4](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/kevin4/32/59688_2.png) [@kevin4](https://forum.bubble.io/u/kevin4)\
**Post date:** [January 26, 2023, 7:23pm UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/1 "2023-01-26T19:23:26Z")

</div>

I’m writing a server-side plugin that returns an object, and after working through the context.async syntax and getting the plugin to return on an object, I now have a new and interesting issue.

I know the plugin returns the object I want because there is a console.log() statement in the plugin that outputs it to the server log.

The console.log() statement is below.

```auto
 console.log("CustomPlugin:getLinks:objectToReturn:try3: ", objectToReturn)

```

And I can see the object from that statement in the server log, as shown below.

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/b/2/b29bd27e1b77a5b35a227544316cb207fbdb0384.png)

However, as the plugin is not fully done, I’m taking baby steps and testing it again after each code addition.

I want to, within Bubble, stringify the object so I can display it in a Text element.

And herein lies the problem.

I’ve experimented with:  
Javascript Toolbox - Run javascript  
Javascript Toolbox - Server Script  
jsoNest Plugin for Bubble

But I’m not figuring out how to address or reference the object correctly.

For example, here is a screenshot of me trying to use Run javascript to simply “console.log()” the object, which in a browser or a Node JS script, just works.  
 ![image](https://us1.discourse-cdn.com/bubble/original/3X/8/9/89bc4faca73ea7d5b50fe86550bbfa74eac7155b.png)

The issue is that the object is not text, which of course it isn’t.

For what it’s worth, Bubble did create an object property named “raw body text” that I did not define, and I tried it, but it seems to be always empty.

Does anyone know how to do a

```auto
let objectTextRepresentation = JSON.stringify(object)
console.log(objectTextRepresentation)

```

in Bubble?

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/dorilama/32/226878_2.png) [@dorilama](https://forum.bubble.io/u/dorilama)\
**Post date:** [January 26, 2023, 7:50pm UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/2 "2023-01-26T19:50:57Z")

</div>

You don’t access the whole returned object but you can access its properties. Try “result of step1 propertyX”

---

<div class="post-metadata">

**Author:** ![kevin4](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/kevin4/32/59688_2.png) [@kevin4](https://forum.bubble.io/u/kevin4)\
**Post date:** [January 26, 2023, 11:44pm UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/3 "2023-01-26T23:44:24Z")

</div>

There is one text field within the object. If I grab it, I get it.

But I want to see the full object in JSON format.

---

<div class="post-metadata">

**Author:** ![kevin4](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/kevin4/32/59688_2.png) [@kevin4](https://forum.bubble.io/u/kevin4)\
**Post date:** [January 26, 2023, 11:47pm UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/4 "2023-01-26T23:47:38Z")

</div>

I could also perform the JSON.stringify() within the plugin and return a JSON object, but Bubble seems “happy” with the object, and I’m not sure how returning a JSON object would affect things.

Do you know?

---

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [January 27, 2023, 1:55am UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/5 "2023-01-27T01:55:55Z")

</div>

The Bubble plugin API(s) don’t support arbitrary object publishing. But of course the SSA plugin API essentially returns an object. The individual fields of primitive or app types are what you would return as the fields defined under “Return types”.

---

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [January 27, 2023, 1:57am UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/6 "2023-01-27T01:57:02Z")

</div>

Also moved this to “Plugin Builders” in case another plugin builder might want to assist you more.

---

<div class="post-metadata">

**Author:** ![kevin4](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/kevin4/32/59688_2.png) [@kevin4](https://forum.bubble.io/u/kevin4)\
**Post date:** [January 27, 2023, 3:17am UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/7 "2023-01-27T03:17:48Z")

</div>

I thought of a strange way of possibly doing this, and interestingly enough, it worked.

I added a field to returnedObject. It’s \_p\_stringified.

```auto
    let objectToReturn = {
        _p_links: [
            {
                _p_href: "Here ye, here ye, the answer is always 42!",
                _p_rel: "",
                _p_text: ""
            }
        ],
        _p_stringified: "",
        _p_returnStatus: null,
        _p_returnStatusText: ""
    }

```

Then, after the object is “fully constructed” I ran JSON.stringify() in order to place a stringfiied copy of the object into that field within the object.

The reason I was uncertain if it would work is it seems to weird to place a “snapsnot” of an object into a field of the object the snapshot is being taken off.

```auto
 objectToReturn._p_stringified = JSON.stringify(objectToReturn)

```

But, it worked. I can now visually see the object is complete and intact.

---

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [January 27, 2023, 3:26am UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/8 "2023-01-27T03:26:36Z")

</div>

You’re going to have to take this particular hack up with @jared.gibb. I have no idea how they figured out the prefix thing (or who explained that to then), but my jam is making generally useful Bubble plugins for the community, not custom hacks for specific apps which is where your particular use case goes. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [January 27, 2023, 3:27am UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/9 "2023-01-27T03:27:59Z")

</div>

ADDITIONALLY: I can tell you’re just thrashing around. It’s not magic you’re doing here, it’s development. Don’t guess at shit. Go learn it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [April 6, 2023, 7:24pm UTC](https://forum.bubble.io/t/how-do-i-stringify-an-object-in-bubble/243612/10 "2023-04-06T19:24:05Z")

</div>

Closed on April 6, 2023, 7:24pm UTC

This topic was automatically closed after 70 days. New replies are no longer allowed.
