# Degree Symbol not supported in system.util.jsonDecode?

**URL:** <https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [May 7, 2020, 3:02pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527 "2020-05-07T15:02:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![braydon.hancock](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@braydon.hancock](https://forum.inductiveautomation.com/u/braydon.hancock)\
**Post date:** [May 7, 2020, 3:02pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/1 "2020-05-07T15:02:56Z")

</div>

We have a jsonString which contains the degree symbol. When we try to decode that string it errors out, see example code and error below.

Should I be encoding the degree symbol differently? I’ve tried many different formats and can’t seem to make anything work.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4512330955c0b1f0889e0cd7504c67df9fdeffb8.png)

Code:

```auto
deg = '°'
config = [{'degree': deg}]
print config

newConfig = system.util.jsonDecode(str(config))
print newConfig

```

Error results:

```auto
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.6

>>> 
[{'degree': '\xc2\xb0'}]
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 6, in <module>
	at org.json.JSONTokener.syntaxError(JSONTokener.java:430)

	at org.json.JSONTokener.nextString(JSONTokener.java:282)

	at org.json.JSONTokener.nextValue(JSONTokener.java:355)

	at org.json.JSONObject.<init>(JSONObject.java:201)

	at org.json.JSONTokener.nextValue(JSONTokener.java:358)

	at org.json.JSONArray.<init>(JSONArray.java:127)

	at org.json.JSONArray.<init>(JSONArray.java:160)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.jsonDecode(SystemUtilities.java:427)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

org.json.JSONException: org.json.JSONException: Illegal escape. at 15 [character 16 line 1]

	at org.python.core.Py.JavaError(Py.java:552)

	at org.python.core.Py.JavaError(Py.java:543)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)

	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:520)

	at org.python.core.PyObject. __call__ (PyObject.java:480)

	at org.python.core.PyObject. __call__ (PyObject.java:484)

	at org.python.pycode._pyx106.f$0(<input>:7)

	at org.python.pycode._pyx106.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.json.JSONException: Illegal escape. at 15 [character 16 line 1]

	at org.json.JSONTokener.syntaxError(JSONTokener.java:430)

	at org.json.JSONTokener.nextString(JSONTokener.java:282)

	at org.json.JSONTokener.nextValue(JSONTokener.java:355)

	at org.json.JSONObject.<init>(JSONObject.java:201)

	at org.json.JSONTokener.nextValue(JSONTokener.java:358)

	at org.json.JSONArray.<init>(JSONArray.java:127)

	at org.json.JSONArray.<init>(JSONArray.java:160)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.jsonDecode(SystemUtilities.java:427)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:188)

	... 19 more

Traceback (most recent call last):
  File "<input>", line 6, in <module>
	at org.json.JSONTokener.syntaxError(JSONTokener.java:430)

	at org.json.JSONTokener.nextString(JSONTokener.java:282)

	at org.json.JSONTokener.nextValue(JSONTokener.java:355)

	at org.json.JSONObject.<init>(JSONObject.java:201)

	at org.json.JSONTokener.nextValue(JSONTokener.java:358)

	at org.json.JSONArray.<init>(JSONArray.java:127)

	at org.json.JSONArray.<init>(JSONArray.java:160)

	at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.jsonDecode(SystemUtilities.java:427)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

org.json.JSONException: org.json.JSONException: Illegal escape. at 15 [character 16 line 1]

```

---

<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:** [May 7, 2020, 3:08pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/2 "2020-05-07T15:08:29Z")

</div>

By passing `str(config)` to `jsonDecode` you are passing it invalid JSON, because that evaluates to “[{‘degree’: u’\xb0’}]”.

---

<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:** [May 7, 2020, 3:10pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/3 "2020-05-07T15:10:17Z")

</div>

Play with this script to better understand:

```auto
deg = u'°'
config = [{'degree': deg}]
print str(config)

json = system.util.jsonEncode(config)
print json

newConfig = system.util.jsonDecode(json)
print newConfig

```

---

<div class="post-metadata">

**Author:** ![braydon.hancock](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@braydon.hancock](https://forum.inductiveautomation.com/u/braydon.hancock)\
**Post date:** [May 7, 2020, 3:16pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/4 "2020-05-07T15:16:25Z")

</div>

Hey Kevin,

Thanks for your response. I guess this more accurately portrays the situation we are encountering:

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

Can you provide recommendation on how to convert that back to a simple degree symbol?

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [May 7, 2020, 3:18pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/5 "2020-05-07T15:18:09Z")

</div>

> [@Kevin.Herron](#):
>
> deg = u'°' config = [{'degree': deg}] print str(config) json = system.util.jsonEncode(config) print json newConfig = system.util.jsonDecode(json) print newConfig

if you use the code kevin provided then your print will have the degree symbol

---

<div class="post-metadata">

**Author:** ![braydon.hancock](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@braydon.hancock](https://forum.inductiveautomation.com/u/braydon.hancock)\
**Post date:** [May 7, 2020, 3:20pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/6 "2020-05-07T15:20:09Z")

</div>

That is correct, but the jsonEncode turns it into a string. We need it in a json object.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 7, 2020, 3:23pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/7 "2020-05-07T15:23:37Z")

</div>

> [@braydon.hancock](#):
>
> That is correct, but the jsonEncode turns it into a string. We need it in a json object.

The degree symbol also needs a unicode descriptor.

```auto
config = [{'degree': u'°'}]

```

---

<div class="post-metadata">

**Author:** ![braydon.hancock](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@braydon.hancock](https://forum.inductiveautomation.com/u/braydon.hancock)\
**Post date:** [May 7, 2020, 3:39pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/8 "2020-05-07T15:39:30Z")

</div>

A couple more examples for context.

This is ultimately what I’m trying to do:

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

If I use u’ descriptor:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0870c37fae904b4688c1b3c3ac0a497e1cae23d9.png)

Edit: updated image for unicode descriptor

---

<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:** [May 7, 2020, 3:43pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/9 "2020-05-07T15:43:33Z")

</div>

Neither `[{'degree': '°F'}]` nor `[{'degree': u'°F'}]` are legal JSON.

Your first line should be `config = u'[{"degree": "°F"}]'` - you need to mark your entire JSON string as unicode so that the Jython interpreter doesn’t try to fold down to ASCII. Similarly, any string literal containing a non-ASCII character (such as line 9, with a comparison against `"°F"` - should be prefixed with `u`. That’s a _Python 2_ constraint, and has nothing to do with JSON, and doesn’t belong in your actual JSON.

---

<div class="post-metadata">

**Author:** ![braydon.hancock](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@braydon.hancock](https://forum.inductiveautomation.com/u/braydon.hancock)\
**Post date:** [May 7, 2020, 3:46pm UTC](https://forum.inductiveautomation.com/t/degree-symbol-not-supported-in-system-util-jsondecode/34527/10 "2020-05-07T15:46:51Z")

</div>

Thank you, sir! This fixed my problem. Appreciate the help.

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