# MalformedJsonException: Use JsonReader.setLenient(true)

**URL:** <https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [November 2, 2021, 10:52pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650 "2021-11-02T22:52:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [November 2, 2021, 10:52pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/1 "2021-11-02T22:52:56Z")

</div>

v8.1.11

I keep getting this error when I try to decode a JSON object from a response body:

```auto
Traceback (most recent call last):
  File "<input>", line 14, in <module>
ValueError: Unable to parse response body as JSON: com.inductiveautomation.ignition.common.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2 path $

```

Here is my script:

```python
client = system.net.httpClient()
url = "https://api.dailymotion.com/file/upload"
headers = {
	"Accept": "application/json",
	"Accept-Encoding": "gzip, deflate, br",
	"Authorization": "Bearer <TOKEN>"
}
res = client.get(url, headers=headers)
print res.good # returns True

```

Is there any way I can fix this?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 10:54pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/2 "2021-11-02T22:54:12Z")

</div>

Is it actually malformed? Do you have an example of it?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [November 2, 2021, 10:56pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/3 "2021-11-02T22:56:03Z")

</div>

Not in Postman. Here is the response:

```json
{
    "upload_url": "<url>",
    "progress_url": "<url>"
}

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 10:57pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/4 "2021-11-02T22:57:22Z")

</div>

Can you post your whole script? The error references line 14 but there’s not 14 lines in the script you posted.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [November 2, 2021, 10:59pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/5 "2021-11-02T22:59:42Z")

</div>

It was this line (I cleaned it up when I added to post above):

```python
print res.getJson() # res.json returns the same thing

```

Here is what else I tried (based on SO answers):

```python
from com.inductiveautomation.ignition.common.gson import GsonBuilder
client = system.net.httpClient()
altGson = GsonBuilder().setLenient().create()
client.setGson(altGson)
...

```

Same thing happens.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 11:00pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/6 "2021-11-02T23:00:49Z")

</div>

Hmm, I was going to suggest basically that:

```auto
new_gson = client.getGson().newBuilder().setLenient().create()
client.setGson(new_gson)

```

Try printing `str(res.getBody())` or something instead.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [November 2, 2021, 11:05pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/7 "2021-11-02T23:05:25Z")

</div>

`getBody()` returns data, as far as I can tell. I added the code you included above but still get the same error when I try to `getJson()`.

Also, this is happening in the script console, if that matters. It wasn’t working on a button event, so I’m now investigating.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 11:07pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/8 "2021-11-02T23:07:03Z")

</div>

Does the above print out the JSON you’re getting or just a string rep of the bytes?

Might need something like this instead:

```auto
from java.lang import String

print String(res.getBody())

```

Trying to see the contents of the body without parsing it.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [November 2, 2021, 11:10pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/9 "2021-11-02T23:10:45Z")

</div>

A bunch of gibberish (even though response says it is UTF-8 encoded).

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9a057e7dfbcc4ae7435bd3d4833a55a252a1d41d.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 11:12pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/10 "2021-11-02T23:12:55Z")

</div>

Huh. Not sure what else to try. You probably _are_ getting a body that isn’t JSON, but I don’t know why.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 11:18pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/11 "2021-11-02T23:18:41Z")

</div>

A little facepalm for future readers: there is a `getText()` method on the response object.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2021, 11:23pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/12 "2021-11-02T23:23:17Z")

</div>

Okay, one last suggestion: remove your gzip/deflate/br headers.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [November 2, 2021, 11:25pm UTC](https://forum.inductiveautomation.com/t/malformedjsonexception-use-jsonreader-setlenient-true/52650/13 "2021-11-02T23:25:25Z")

</div>

Boom. That was it 🤦‍♂️ Thanks Kevin!
