# Copy json dictionary without unicode delimiters

**URL:** <https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157>\
**Category:** Ignition\
**Created:** [June 29, 2020, 2:31pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157 "2020-06-29T14:31:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 29, 2020, 2:31pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/1 "2020-06-29T14:31:56Z")

</div>

I am using a document memory tag to store some recipe information, and there is a “bug” right now with that tag type that requires you to cast the value to a string, and then jsonDecode it to use it as a dictionary.  
i.e.

```auto
json = system.util.jsonDecode(str(system.tag.readBlocking([tagPath])[0].value))

```

But somewhere along the way the keys in the dictionaries are made into unicode, instead of strings, so you have the `u'` appended to the beggining of each key.

i.e.

```auto
{u'example':1234, u'example2':[1,2,3,4,5]}

```

Is there an easy way to convert all of them to regular strings? I know I can do a `.replace("u'", "'")` on it while its a string, but that is not necessarily a very clean solution.

Any ideas?

---

<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:** [June 29, 2020, 2:38pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/2 "2020-06-29T14:38:28Z")

</div>

That ‘u’ isn’t actually there in the string value, it’s only there in the toString representation you see when printing the dictionary.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 29, 2020, 2:42pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/3 "2020-06-29T14:42:03Z")

</div>

Gotcha,

I am trying to copy my json to review it in a formatted editor like VSCode, and I just wasnt able to find a way to copy it without those included.

Is there a way to print it in a way that doesnt show the `u` for the unicode so that I can copy it without them?

EDIT: OR if I am able to print formatted json in the script console, just didnt think I could do that

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 29, 2020, 2:44pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/4 "2020-06-29T14:44:30Z")

</div>

Actually,

I just needed to grab it prior to encoding it into a dictionary, so in this example, I would copy the print from documentString

```auto
tagPath = "[default]Testing/Recipe"
documentTag = system.tag.readBlocking([tagPath])[0].value
print documentTag
documentUnicodeString = str(documentTag)
print documentString #Copy me for a JSON editor!
documentJSON = system.util.jsonDecode(documentString)
print documentJSON

```

---

<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:** [June 29, 2020, 2:44pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/5 "2020-06-29T14:44:38Z")

</div>

Just print the document without turning it to a dictionary.

edit: yep you got it.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 29, 2020, 2:45pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/6 "2020-06-29T14:45:24Z")

</div>

What timing,

Thanks for the clarification on the presence of the `u` kevin!

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 19, 2020, 11:31am UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/7 "2020-07-19T11:31:52Z")

</div>

Continuing on the topic, I just want to get a JSON for tags using in a script (in version 8)

```python
		tags = system.tag.getConfiguration(path,True)
		print tags

```

for one of my memory tags '**[default]Tag 0**' from DB. I get the following in log file

`[{u'dataType': Float4, u'documentation': u'Boiler Pressure', u'alarms': [{u'setpointA': 75.0, u'label': u'High', u'mode': Above Setpoint, u'name': u'High'}, {u'setpointA': 10.0, u'label': u'Very Low', u'mode': Below Setpoint, u'name': u'Very Low'}, {u'setpointA': 20.0, u'mode': Below Setpoint, u'name': u'Low'}, {u'setpointA': 80.0, u'label': u'Very High', u'mode': Above Setpoint, u'name': u'Very High'}], u'path': [default]Tag 0, u'tagType': AtomicTag, u'name': u'Tag 0', u'engUnit': u'psi', u'valueSource': u'memory', u'value': 80.0}]`

I want the output value 'tags' in JSON without the unicode characters! I can understand tag properties in unicode in order to facilitate localization in diifferent languages , but why are all keys also converted to unicode? Basically I am trying to generate a JSON array for a given list of tags of my choice from my DB, so that I can export the JSON to another Ignition DB for further processing. How can I do that?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 19, 2020, 12:55pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/8 "2020-07-19T12:55:33Z")

</div>

The u’’ syntax is a printing/logging artifact. Strings in java are natively unicode, so that representation is the default conversion in jython. Note that `getConfiguration` isn’t returning JSON, it is returning a python list of python dictionaries. (Documented to do so, if you didn’t notice.) You would need to use jsonEncode or your own equivalent to yield JSON.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 19, 2020, 1:49pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/9 "2020-07-19T13:49:32Z")

</div>

While converting dictionary to JSON using json.dumps(), some of the values in key/value pairs are enums such as Float4, the alarm properties etc which give error such as cannot be serialized! I guess we have to individually convert each key/value pair, there is no simple one function that will do the JSON conversion for this use case! Or is there any ? I don't know where to find jsonEncode documentation in scripting functions!

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [July 19, 2020, 1:54pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/10 "2020-07-19T13:54:14Z")

</div>

> [@prafull\_j](#):
>
> I don’t know where to find jsonEncode documentation in scripting functions!

[https://docs.inductiveautomation.com/display/DOC80/system.util.jsonEncode](https://docs.inductiveautomation.com/display/DOC80/system.util.jsonEncode)

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 19, 2020, 2:34pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/11 "2020-07-19T14:34:49Z")

</div>

Thanks for the link. But I get an error 'RuntimeError: maximum recursion depth exceeded (Java StackOverflowError)' I think I have given a large dictionary object ! I will try some smaller object.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 19, 2020, 2:59pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/12 "2020-07-19T14:59:39Z")

</div>

The function system.tag.exportTags works fine, but alas its only for version 8. Wish there was some thing like this for at least 7.9.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [July 20, 2020, 3:26am UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/13 "2020-07-20T03:26:51Z")

</div>

> [@prafull\_j](#):
>
> But I get an error ‘RuntimeError: maximum recursion depth exceeded (Java StackOverflowError)’ I think I have given a large dictionary object !

Actually this typically comes from giving the jsonEncode function a dictionary that includes a class instance of something that serializses in a non-json structure. For instance if one of your values is a BasicQualifiedValue then it will return this. I’m not exactly sure what your dictionary looks like prior to encoding, but you could potentially iterate through it and convert any BasicQualifiedValues to regular values

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 20, 2020, 5:13am UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/14 "2020-07-20T05:13:36Z")

</div>

> [@prafull\_j](#):
>
> [{u'dataType': **Float4** , u'documentation': u'Boiler Pressure', u'alarms': [{u'setpointA': 75.0, u'label': u'High', u'mode': **Above Setpoint** , u'name': u'High'}, {u'setpointA': 10.0, u'label': u'Very Low', u'mode': **Below Setpoint** , u'name': u'Very Low'}, {u'setpointA': 20.0, u'mode': Below Setpoint, u'name': u'Low'}, {u'setpointA': 80.0, u'label': u'Very High', u'mode': Above Setpoint, u'name': u'Very High'}], u'path': [default]Tag 0, u'tagType': AtomicTag, u'name': u'Tag 0', u'engUnit': u'psi', u'valueSource': u'memory', u'value': 80.0}]

As given before, the dictionary is basically a tag properties dictionary generated by function **system.tag.getConfiguration(basePath, recursive)** in version 8. I think, things like **Float4** , **Above setpoint** , **Below Setpoint** etc are enums which are I think not parsable to JSON. It will be nice if I can get the properties of selected tags as JSON somehow, just like the system.tag.exportTags function in version 8, exports JSON for a given folder to a file. Sample JSON:

[  
{  
"valueSource": "memory",  
"dataType": "Float4",  
"documentation": "Hotwell Level",  
"alarms": [  
{  
"mode": "AboveValue",  
"setpointA": 75.0,  
"name": "High",  
"label": "High"  
},  
{  
"mode": "BelowValue",  
"setpointA": 10.0,  
"name": "Very Low",  
"label": "Very Low"  
},  
{  
"mode": "BelowValue",  
"setpointA": 20.0,  
"name": "Low",  
"label": "Low"  
},  
{  
"mode": "AboveValue",  
"setpointA": 80.0,  
"name": "Very High",  
"label": "Very High"  
}  
],

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [July 20, 2020, 10:28am UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/15 "2020-07-20T10:28:06Z")

</div>

Try replacing the memory tag value at the end of the JSON before converting it, I am able to parse json with floats and what not in it.

In your case before the encode hardcode it with something like `tags[0][‘value’] = 80` And see if that works.

As well the ‘path’ variable may be a BasicTagPath and not a string so you could try overwriting that as a string as well.

If those two solve it, it would be pretty easy to write a recursive script that goes through all of it to find oddly typed values like that and convert them

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 24, 2020, 4:23pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/17 "2020-07-24T16:23:19Z")

</div>

> [@prafull\_j](#):
>
> . I think, things like **Float4** , **Above setpoint** , **Below Setpoint** etc are enums which are I think not parsable to JSON.

The problem is solved by simply casting these enums to string in python. It is producing the python dictionary which is parsable to JSON properly now! It was a simple problem!

---

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [August 29, 2020, 6:36pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/18 "2020-08-29T18:36:09Z")

</div>

Hi @PRAMANJ , @kgamble

Can you help to solve this for me?  
I need to write back the dictionary value to tag.

```
userName = self.session.props.auth.user.userName

rawTagdata = system.tag.readBlocking(["[default]NOCTANKMONITOR/PersonalTrend"])
system.perspective.print (rawTagdata)

personalTrendTags = rawTagdata[0].value.toDict()

personalAxes = self.view.custom.axes
personalColors = self.view.custom.colors
personalPens = self.view.custom.pens
personalTags = self.view.custom.tags

personalTrendTags[userName] = {"axes":personalAxes, "colors":personalColors , "pens":personalPens, "tags":personalTags}
system.perspective.print (personalTrendTags)

newTagdata = []
newTagdata.append(personalTrendTags)
system.perspective.print (newTagdata)

encodedTag = system.util.jsonEncode(newTagdata)
system.tag.writeBlocking(["[default]NOCTANKMONITOR/PersonalTrend"], [encodedTag])

```

I’m getting same error as “RuntimeError: maximum recursion depth exceeded (Java StackOverflowError)” at system.util.jsonEncode script.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [August 30, 2020, 2:38pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/19 "2020-08-30T14:38:23Z")

</div>

> [@guganathan.r](#):
>
> Can you help to solve this for me

If you look through the output printed by the third print statement, you will notice that there are alot of objectWrappers for each of the color properties:

```auto
... 
<ObjectWrapper>: {u'color': u'rgba(151,242,24,1)', u'pen': None},
<ObjectWrapper>: {u'color': u'rgba(242,24,215,1)', u'pen': None},
<ObjectWrapper>: {u'color': u'rgba(24,242,205,1)', u'pen': None},
...

```

The `system.util.jsonEncode()` function is not a fan of wrappers I have found, same happens when you pass a `BasicQualifiedValue`

Unfortunately these wrappers seem to be present on each of the objects within array properties. So to use them you will just need to cast them as dictionaries (and a list in the case of the tags)

Replace lines 8-11 with the following

```auto
personalAxes = [dict(axis) for axis in self.view.custom.axes]
personalColors = [dict(color) for color in self.view.custom.colors]
personalPens = [dict(pen) for pen in self.view.custom.pens]
personalTags = list(self.view.custom.tags)

```

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [August 30, 2020, 2:39pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/20 "2020-08-30T14:39:46Z")

</div>

> [@kgamble](#):
>
> you will notice that there are alot of objectWrappers for each of the color properties

Note:  
I am not sure if this is considered a bug or not, because I can see almost no end user scenario where the preferred behavior would be to copy the wrapper and not a dictionary? However there may be some functional limitations here that I am unaware of causing this to be a necessity

---

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [August 30, 2020, 2:52pm UTC](https://forum.inductiveautomation.com/t/copy-json-dictionary-without-unicode-delimiters/36157/21 "2020-08-30T14:52:17Z")

</div>

@kgamble Thanks a lot! I got your point. 👍
