# Issue with JavaScript Column not returning output

**URL:** <https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190>\
**Category:** Ask for Help\
**Created:** [June 17, 2024, 8:53pm UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190 "2024-06-17T20:53:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewjaustin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/andrewjaustin/32/76676_2.png) [@andrewjaustin](https://community.glideapps.com/u/andrewjaustin)\
**Post date:** [June 17, 2024, 8:53pm UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/1 "2024-06-17T20:53:20Z")

</div>

Hi there, I’m not super proficient with JavaScript, but am looking to use the JS column to convert a JSON object with a quantity property into multiple JSON objects, which I _believe_ should work.

The following code works in JSFiddle, but I’m not returning any results in the Glide column (nor any errors):

```auto
function parseCart() {
  let initialObject = p1;
  let outputObjects = [];
  for (let i = 0; i < initialObject.quantity; i++) {
    outputObjects.push(JSON.stringify({
      id: initialObject.id,
      item: initialObject.item
    }, null, 2));
  }
  return outputObjects.join(',');
}
return parseCart();

```

`p1` is referencing a column with JSON that is formatted like so:

```auto
{
  "id": "foo",
  "item": "Item Title",
  "quantity": 2
}

```

My desired output is to take the JSON object from p1 and split it into individual objects based on the quantity value:

```auto
{
  "id": "foo",
  "item": "Item Title"
},
{
  "id": "foo",
  "item": "Item Title"
}

```

Any assistance or pointing in the right direction would be so appreciated — thanks in advance!

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [June 17, 2024, 9:21pm UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/2 "2024-06-17T21:21:19Z")

</div>

You are trying to return an array. In Glide, you can only return strings. You need to add a `.join()` to the end of the array object. This should return all JSON objects as a comma delimited string.

---

<div class="post-metadata">

**Author:** ![andrewjaustin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/andrewjaustin/32/76676_2.png) [@andrewjaustin](https://community.glideapps.com/u/andrewjaustin)\
**Post date:** [June 18, 2024, 1:20am UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/3 "2024-06-18T01:20:07Z")

</div>

@Jeff_Hager thanks so much for the quick reply! Apologies if I’m misunderstanding, but isn’t that what’s occurring with the line:

```auto
return outputObjects.join(',');

```

Or perhaps the `.join()` should be placed elsewhere instead?

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [June 18, 2024, 2:18am UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/4 "2024-06-18T02:18:47Z")

</div>

Apologies. I glanced at your code quickly and missed the join. I thought it was just returning the full array.

If I were to guess again… 😜  
I think it might be your input. It looks like the JSON string isn’t being turned into an object so initialObject is just text and doesn’t have a quantity attribute. I’ll play around a bit to see if that’s the case.

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [June 18, 2024, 2:35am UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/5 "2024-06-18T02:35:11Z")

</div>

OK, just wanted to verify before I spit more lies.

All you should need to change is the initialObject definition. Change it to this:  
`let initialObject = JSON.parse(p1);`

---

<div class="post-metadata">

**Author:** ![andrewjaustin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/andrewjaustin/32/76676_2.png) [@andrewjaustin](https://community.glideapps.com/u/andrewjaustin)\
**Post date:** [June 18, 2024, 2:59am UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/6 "2024-06-18T02:59:26Z")

</div>

That worked beautifully — thank you very much for the help!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [June 19, 2024, 12:20am UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/7 "2024-06-19T00:20:15Z")

</div>

To clarify, it didn’t work initially because the JSON that you use as input is seen as a string, and not a JSON object, so you have to parse it first.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [June 26, 2024, 12:21am UTC](https://community.glideapps.com/t/issue-with-javascript-column-not-returning-output/74190/8 "2024-06-26T00:21:13Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
