# Why am I (sometimes) getting a bad json error. Status code 400

**URL:** <https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416>\
**Category:** API\
**Created:** [October 1, 2023, 7:16pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416 "2023-10-01T19:16:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve48](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Steve48](https://community.openai.com/u/Steve48)\
**Post date:** [October 1, 2023, 7:16pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/1 "2023-10-01T19:16:52Z")

</div>

In Power Automate Desktop, I am looping through similar pdf files and using the GPT-4 API To extract text from them, Some files return status code 200 and some return 400 -bad json. I copied the text out of the ‘bad’ file that gets submitted to the API into the playground and it got processed with no error, Does anyone have any idea of how to troubleshoot. Why would playground process ok but not the API? TIA

---

<div class="post-metadata">

**Author:** ![ramn7](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ramn7/32/195226_2.png) [@ramn7](https://community.openai.com/u/ramn7)\
**Post date:** [October 1, 2023, 8:02pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/2 "2023-10-01T20:02:32Z")

</div>

I’m not familiar with this exact error (or the environment tbh) but I’d guess it could possibly something related to weird characters/escaping of the input string.  
To troubleshoot I’d try to pretty print the relevant part of your request object in the environment you’re working in (something like `JSON.stringify(obj, null, 2)` in js) to see what it looks like there and try to understand what’s might be wrong with it.

---

<div class="post-metadata">

**Author:** ![Steve48](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Steve48](https://community.openai.com/u/Steve48)\
**Post date:** [October 1, 2023, 8:19pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/3 "2023-10-01T20:19:53Z")

</div>

Why wouldn’t it fail in playground

---

<div class="post-metadata">

**Author:** ![ramn7](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ramn7/32/195226_2.png) [@ramn7](https://community.openai.com/u/ramn7)\
**Post date:** [October 1, 2023, 8:37pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/4 "2023-10-01T20:37:28Z")

</div>

not sure 😅 possibly something related to the way the original environment parses the string, or when it’s copied, or pasted in the playground. Anyway it’s just an idea on how to troubleshoot- looking into the issue in the original environment.

---

<div class="post-metadata">

**Author:** ![Steve48](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Steve48](https://community.openai.com/u/Steve48)\
**Post date:** [October 1, 2023, 9:05pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/5 "2023-10-01T21:05:24Z")

</div>

The original environment is power automate desktop. I am copying the string that I input to the playground after it has been parsed by power automate desktop so it doesn’t seem parsing can be the problem. I see that playground may use parameters that I didn’t use, such as top\_1, frequency penalty, presence penalty, but I don’t think that should make a difference. I’m going to use postman to see if I can get some insight.

---

<div class="post-metadata">

**Author:** ![Steve48](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Steve48](https://community.openai.com/u/Steve48)\
**Post date:** [October 1, 2023, 10:03pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/6 "2023-10-01T22:03:17Z")

</div>

Thank you for your interest and help. In postman, the text was underlined with squiggles indicating it was invalid. By successive truncations I was able to determine that. ‘\” in the string was the culprit.

---

<div class="post-metadata">

**Author:** ![jwatte](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jwatte/32/127705_2.png) [@jwatte](https://community.openai.com/u/jwatte)\
**Post date:** [October 1, 2023, 11:16pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/7 "2023-10-01T23:16:02Z")

</div>

The playground will quote your input strings for you. When you make JSON yourself, you have to properly quote the string values you put in. Most libraries will also do this for you, but if you formulate the JSON encoding yourself, you have to properly encode special characters yourself.

---

<div class="post-metadata">

**Author:** ![Steve48](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Steve48](https://community.openai.com/u/Steve48)\
**Post date:** [October 2, 2023, 1:13am UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/8 "2023-10-02T01:13:17Z")

</div>

Thank you. That’s helpful.

---

<div class="post-metadata">

**Author:** ![Steve48](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Steve48](https://community.openai.com/u/Steve48)\
**Post date:** [October 2, 2023, 1:14am UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/9 "2023-10-02T01:14:02Z")

</div>

Thank you. That’s helpful

---

<div class="post-metadata">

**Author:** ![ramn7](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ramn7/32/195226_2.png) [@ramn7](https://community.openai.com/u/ramn7)\
**Post date:** [October 2, 2023, 8:25am UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/10 "2023-10-02T08:25:25Z")

</div>

Cool and makes sense 🙂 Happy to hear it was resolved!

---

<div class="post-metadata">

**Author:** ![EricGT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ericgt/32/20571_2.png) [@EricGT](https://community.openai.com/u/EricGT)\
**Post date:** [December 15, 2023, 7:22pm UTC](https://community.openai.com/t/why-am-i-sometimes-getting-a-bad-json-error-status-code-400/407416/11 "2023-12-15T19:22:36Z")

</div>

Closed on December 15, 2023, 7:22pm UTC


