# Is there a way to remove the extra characters from JSON result?

**URL:** https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606
**Category:** Ask for Help
**Created:** [December 12, 2023, 12:42pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606 "2023-12-12T12:42:43Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![smaxss](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/smaxss/32/61057_2.png) [@smaxss](https://community.glideapps.com/u/smaxss)
#### Post date: [December 12, 2023, 12:42pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/1 "2023-12-12T12:42:44Z")

</div>

Hi,  
I’m using the OpenAI output as JSON, however it being wrapped in comments that are not recognised by the parser.  
Is there any way to avoid this without too many loops with trimming the text?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/b/8b9e830ec320472d85e3d2b38c0a00f03a3fca85.png)

At the end I want to split the result into different columns, like below

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/c/6ca1237d31fd879148435a3c00aafd5bb682be50.png)

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [December 12, 2023, 12:49pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/2 "2023-12-12T12:49:14Z")

</div>

Are you referring to the backticks?  
What does your prompt look like?  
You should be able to craft it so that only the JSON is returned.

---

<div class="post-metadata">

### Author: ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)
#### Post date: [December 12, 2023, 12:53pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/3 "2023-12-12T12:53:14Z")

</div>

This is not a JSON format… how did you get it? What kind of script?.. You can clean it by replacing the first characters… anything before the first curly bracket must go away…

---

<div class="post-metadata">

### Author: ![smaxss](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/smaxss/32/61057_2.png) [@smaxss](https://community.glideapps.com/u/smaxss)
#### Post date: [December 12, 2023, 12:57pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/4 "2023-12-12T12:57:05Z")

</div>

yes, these backticks are causing me an issue.

I’m using output from OpenAi integration with the following prompt (part is shown)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/2/32fa454a8397cf7c437326e9ad8571efb5eae324.png)

There is also an option to return in JSON, which makes no difference in this case.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/b/7be61b652452b3ca0547aa41768b6a6ca08b5688.png)

---

<div class="post-metadata">

### Author: ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)
#### Post date: [December 12, 2023, 1:14pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/5 "2023-12-12T13:14:26Z")

</div>

Replace your code with this one:

```auto
if(p1){
let inputString = p1;
let indexOfFirstCurlyBracket = inputString.indexOf('{');

if (indexOfFirstCurlyBracket !== -1) {
  let resultString = inputString.substring(indexOfFirstCurlyBracket);

return (JSON.parse(resultString).json.Title);
} else {
 return "Curly bracket not found in the string."
}
}
return

```

---

<div class="post-metadata">

### Author: ![smaxss](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/smaxss/32/61057_2.png) [@smaxss](https://community.glideapps.com/u/smaxss)
#### Post date: [December 12, 2023, 1:52pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/6 "2023-12-12T13:52:48Z")

</div>

Thank you for suggestion. I tried this code, but it did not work in the JS column. However it gave me an idea to construct a different code which did work at the end without adding interim columns

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/6/26b2ff7d3ea961b41238ca6e6c851d48a6d763b4.png)

---

<div class="post-metadata">

### Author: ![swathi](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@swathi](https://community.glideapps.com/u/swathi)
#### Post date: [March 4, 2025, 7:38am UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/7 "2025-03-04T07:38:25Z")

</div>

This is to remove the invalid char at the start  
How to remove invalid chars at the start before { as well as after }

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [March 4, 2025, 8:14am UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/8 "2025-03-04T08:14:03Z")

</div>

This is a very old thread. Can you please explain more about your use case?  
Please show the data you have, how you get it, and your desired end ressult.

---

<div class="post-metadata">

### Author: ![swathi](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@swathi](https://community.glideapps.com/u/swathi)
#### Post date: [March 4, 2025, 9:18am UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/9 "2025-03-04T09:18:48Z")

</div>

From the AI response we will get json like below  
“Here is the sample response{“productId”: 123, “productCode”:“code1”} end”  
Need to remove prefix text “Here is the sample response” as well as suffix text at end after last } which is “end”

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [March 4, 2025, 9:27am UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/10 "2025-03-04T09:27:11Z")

</div>

Change your prompt. Instruct the AI to return only the JSON and nothing else.

Question: Are you using “Document to Text” or “Generate Text”? If so, try using “Text to JSON” instead.

---

<div class="post-metadata">

### Author: ![swathi](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@swathi](https://community.glideapps.com/u/swathi)
#### Post date: [March 4, 2025, 10:02am UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/11 "2025-03-04T10:02:58Z")

</div>

Yes but sometimes the prompt return invalid text at start and end if promptInput is not proper  
The prompt input is unstructured like “123 code1” then it returns output in json  
{“productId”: 123, “productCode”:“code1”}

---

<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: [March 4, 2025, 11:21pm UTC](https://community.glideapps.com/t/is-there-a-way-to-remove-the-extra-characters-from-json-result/68606/12 "2025-03-04T23:21:07Z")

</div>

You should use Text to JSON to ensure the JSON output.
