# system.net.httpClient automatic JSON handling causing issues

**URL:** <https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 18, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571 "2021-02-18T15:46:04Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 18, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/1 "2021-02-18T15:46:04Z")

</div>

My endpoint is expecting a decimal and for some reason when the httpclient is sending the json it’s turning my numbers to literals. I’m not sure how to get it to not wrap those in quotes.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2e6261edf1067debf4a8bd92c0776b0731641f74.png)

Previously using the httplib I was dumping the JSON to a string and sending it manually and that was working as it should.

I have tried seeing if I can force it to a decimal when I generate the JSON but that didn’t make a difference. What else might I try for this?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/b/5b1b4565515185321ae342905ceee7abf025c753.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:** [February 18, 2021, 3:48pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/2 "2021-02-18T15:48:29Z")

</div>

Does this work?

```auto
data = {
  'key': float(value)
}

```

Not sure what type “Edm.Decimal” is, though. You may be missing some information.

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 18, 2021, 4:17pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/3 "2021-02-18T16:17:06Z")

</div>

> [@Kevin.Herron](#):
>
> Does this work? [float]

Unfortunately no that didn't work same issue.

> [@Kevin.Herron](#):
>
> Not sure what type “Edm.Decimal” is, though

That is the Entity Data Model or EDM (C#/.NET land which is the Epicor base framework I'm sending to) type that our ERP system is expecting:

```auto
data = {
   Number01: 12345.00
}

```

What it is getting:

```auto
data = {
   Number01: '12345'
}

```

---

<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:** [February 18, 2021, 4:30pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/4 "2021-02-18T16:30:00Z")

</div>

```auto
val = 3

data = {
  'foo': float(val)
}

print system.util.jsonEncode(data)

```

Results:

```auto
{"foo":3.0}
>>> 

```

Check the JSON being sent like this. Only way I could see it being a literal is with your use of Decimal or `str` or if the variable is actually a string and you don’t convert it with `float()`.

edit: Hmm, not sure this is a good sanity check after all, the httpClient uses a different method of converting the data to JSON.

---

<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:** [February 18, 2021, 4:40pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/5 "2021-02-18T16:40:29Z")

</div>

Yeah seems to work fine with httpClient as well. You can see it on the wire too:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/4/f4057f398a16628df1627707c675e618d7a6b38d.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 18, 2021, 4:43pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/6 "2021-02-18T16:43:37Z")

</div>

Yeah, `httpbin` gives me what I expect:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/5675fed9b4f582e4e14d78bc0dc9bcd1b8715a8d.png)

I wonder if the single quotes in your logged output aren’t misleading - maybe it is getting a raw number, but the lack of a trailing zero is making it fail to cast?

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 18, 2021, 6:37pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/7 "2021-02-18T18:37:05Z")

</div>

> [@paul-griffith](#):
>
> I wonder if the single quotes in your logged output aren’t misleading - maybe it is getting a raw number, but the lack of a trailing zero is making it fail to cast?

Possibly but what about the old method works that is different from the httpclient I wonder? Below is the old and new way I'm trying to send the data. This is only a portion of the total function, but everything outside of these sections is the same

This is the way I am doing it today and is working as expected

```auto
data = {
					 'Company': "WCI",
					 'Key1': "PLCLoggedData",
					 'Key2': res,
					 'Key3': "",
					 'Key4': "",
					 'Key5': str(int(time.time())),
					 'Date01': datetime.date.today().strftime("%Y-%m-%d"),
					 'Number01': str(seconds_since_midnight),
					 #'Number02': meter,
					 'Number03': bpm,
					 'Number04': bpmtarget,
					 #'Number05': 0.00,
					 'Number06': currmeter,
					 'ShortChar01': jobnum,
					 'CheckBox01': status
				   }

conn = httplib.HTTPSConnection(settings[0].value)
conn.request("POST", "/" + str(settings[1].value).strip() + "/api/v2/odata/WCI/Ice.BO.UD02Svc/UD02s", json.dumps(data), BuildEpicorHeaderInfo(settings))

```

This is the new way I'm trying to do that is causing the error

```auto
payload = {
					 'Company': "WCI",
					 'Key1': "PLCLoggedData",
					 'Key2': res,
					 'Key3': "",
					 'Key4': "",
					 'Key5': str(int(time.time())),
					 'Date01': datetime.date.today().strftime("%Y-%m-%d"),
					 'Number01': seconds_since_midnight,
					 #'Number02': meter,
					 'Number03': bpm,
					 'Number04': bpmtarget,
					 #'Number05': 0.00,
					 'Number06': currmeter,
					 'ShortChar01': jobnum,
					 'CheckBox01': status
				   }

response = httpClient.post(url = BuildEpicorEndpointURL(settings, endpoint), data = payload, params = getvars, headers = BuildEpicorHeaderInfo(settings))

```

I am going to run fiddler on my Epicor server and watch for the incoming request to see the difference between the two. It will take me a bit to setup, but I'll report back later.

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 18, 2021, 7:33pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/8 "2021-02-18T19:33:25Z")

</div>

Even stranger is that the new method is working fine on some calls and not others. In the new method case the POST for tag 405 failed and gave us a 400 error

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/80cc0f9e76338ddd909b3354e406560f6c9ecc2c.png)

But the old method is working on all calls. All 201 responses the old way.

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

It’s the same dictionary in both cases just sent through different libraries so weird! gah!

---

<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:** [February 18, 2021, 7:39pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/9 "2021-02-18T19:39:29Z")

</div>

Once you get fiddler or Wireshark or something that lets you watch the request/response I’m sure the problem will reveal itself.

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 18, 2021, 9:22pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/10 "2021-02-18T21:22:30Z")

</div>

Looks like it’s taking it to an exponent notation using the system.net.httpClient

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/545eb43e198a35db5d29568346781d7f3b0cefcd.png)

This is using the old httplib.HTTPConnection method. No to the E power here

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/d/adda5d29911c90d844c6c5dfc0d581e4fe0c33ce.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:** [February 18, 2021, 10:20pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/11 "2021-02-18T22:20:59Z")

</div>

Hmm. I don’t know if there’s a way to switch it off. The E notation is valid JSON syntax, your backend application is at fault here.

---

<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:** [February 18, 2021, 10:26pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/12 "2021-02-18T22:26:21Z")

</div>

As a workaround, try encoding into a JSON string using `system.util.jsonEncode`. If that appears to encode it without using scientific notation then you can post this JSON string as your data, and you’ll have to explicitly include a Content-Type header for JSON rather than relying on automatic detection.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 18, 2021, 10:26pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/13 "2021-02-18T22:26:35Z")

</div>

You don’t get the benefit of the automatic conversion, but you can always `json.dumps` your dictionary and set the `Content-Type` header appropriately; you still get the other benefits of `httpClient()`

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 19, 2021, 2:47pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/14 "2021-02-19T14:47:15Z")

</div>

Unfortunately, I don’t have any control over how Epicor ICE Framework is parsing the incoming data so I do have to figure it out on the sending side. It will hopefully be quicker than getting a billion dollar developer to pivot LOL.

So that was my next question is can I just send it as a raw string like I have been. Right there with you guys, but you beat me to it!

That being said it seems to be ignoring my supplied content type. Is there another way I should be setting content type other than header dictionary?

I set content type along with my other headers

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

But that is not what is sent through. Is it being overriden?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/4/0490ae2b568642a4f46008f1b376f0f43491aeb8.png)

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 19, 2021, 7:41pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/15 "2021-02-19T19:41:52Z")

</div>

For sanity I created a much smaller isolated script is this a bug I am seeing @Kevin.Herron or @paul-griffith? We are on 8.0.10 if we upgraded would I have the ability to control that header?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5cf49da9425ee25a0933bd65763d790e1e68ff22.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:** [February 19, 2021, 7:59pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/16 "2021-02-19T19:59:44Z")

</div>

> [@wci.jgiese](#):
>
> We are on 8.0.10 if we upgraded would I have the ability to control that header?

Yes, looks like it was a bug fixed in 8.0.15. Any version after that should work.

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 19, 2021, 9:33pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/17 "2021-02-19T21:33:49Z")

</div>

Confirmed that on our 8.1.2 instance all is well. Thanks much! Guess I know what we are doing this weekend 🙂

---

<div class="post-metadata">

**Author:** ![wci.jgiese](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wci.jgiese/32/50225_2.png) [@wci.jgiese](https://forum.inductiveautomation.com/u/wci.jgiese)\
**Post date:** [February 22, 2021, 3:58pm UTC](https://forum.inductiveautomation.com/t/system-net-httpclient-automatic-json-handling-causing-issues/43571/18 "2021-02-22T15:58:07Z")

</div>

We are live on 8.1.2 and can confirm in production the workaround is working just fine. Thank you both! Until next time 🙂
