cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

ThingWorx Navigate is now Windchill Navigate Learn More

Translate the entire conversation x

BUG REPORT: getting a json element whose key contains only digits

BP_9999767
4-Participant

BUG REPORT: getting a json element whose key contains only digits

DESCRIPTION:

Thingworx service does not complete if getting a json element whose key contains only digits.

 

STEPS TO REPRODUCE:

1. Define `test` as a JSON property of a thing
2. Run the following service

 

 

me.test = {"123": "456"}

me.test["123"]
// Java class "org.json.JSONObject" has no public instance field or method named "123"

JSON.parse(JSON.stringify(me.test))["123"]
// Works (workaround)

 

 

 

ERROR MESSAGE:

 

 

Java class "org.json.JSONObject" has no public instance field or method named "123"

 

 

 

VERSION

 9.1.5-b698

 

I'm submitting the bug report here since there is a paywall on the contact us support page and this might be a big issue since it is interpretting the text of the key of the json object as code (or at least as a literal).

ACCEPTED SOLUTION

Accepted Solutions
slangley
23-Emerald III
(To:BP_9999767)

Hi @BP_9999767.

 

A fix for this issue was delivered in ThingWorx 9.4 which is now available for download.

 

Regards.

 

--Sharon

View solution in original post

12 REPLIES 12

 Hi,

 

The error you are experiencing was also discussed in the following thread - "How to convert infoTable to json?": https://community.ptc.com/t5/ThingWorx-Developers/How-to-convert-infoTable-to-json/td-p/520804 

slangley
23-Emerald III
(To:BP_9999767)

Hi @BP_9999767.

 

We tested and were able to recreate the issue.  We also found that we have an open bug report on this.  I am following up for a status and will post it here once I receive more information.

 

Regards.

 

--Sharon

 

slangley
23-Emerald III
(To:BP_9999767)

Hi @BP_9999767.

 

A fix for this issue was delivered in ThingWorx 9.4 which is now available for download.

 

Regards.

 

--Sharon

The issue persists when writing single tags. Assuming the same scenario as in the original post with the test properts, this most simple code will fail with the same error (has no public instance field or method named "123"):

// Fails
me.test["123"] = "456";

// Works
me.test["a123"] = "456";

 

Tested in Version 9.5.6-b1150

wcui
16-Pearl
(To:BennyB)

@BennyB 

per the solution of below article,  we can use JSON.parse method to modify JSON variable.

https://www.ptc.com/en/support/article/CS404027

 

Below code worked on my local TW8.5.3. Can you double check please?

 

me.test["123"] = "456";

var t = JSON.parse(JSON.stringify(me.test));
t["111"]="223";
me.test = t;

BennyB
16-Pearl
(To:wcui)

Hello @wcui ,

 

thanks for your reply. I am certain the suggested code will work but in my opinion this is no solution but a workaround. I already use a workaround by prepending a character, i. e. I get the job done with 

me.test["a123"] = "456";

 

But that doesn't change the fact that I see a bug here which should be tracked and fixed as such.

 

Thank you

BP_9999767
4-Participant
(To:BennyB)

What is crazy to me is that Thingworx evaluates the string.

A fundamental premise of programming is that `"123"` is a string and `123` is a number. I wonder if they run eval on the string.

 

Another interesting bug is that putting `]]>` in a property value makes the entity export to xml fail because it's an XML closing tag for the string. 

Hi @BP_9999767 

Thank you for your supplement to this question. Since the supplement seems to be a different phenomenon, please start a new topic to submit the question. Then other engineers will be responsible for your question.

wcui
16-Pearl
(To:BennyB)

Hi @BennyB , sorry for the late response.

If you would like to have further investigation for this issue, I can open a technical support case on your behalf by using your PTC support account and share the result here once I have any conclusion in the future.

Let me know your choice.

 

 

 

 

BennyB
16-Pearl
(To:wcui)

Hey @wcui ,

 

thank you for your reply and offer. But being frank, I don't care. My workaround does the job and I have other things to do than tracking Thingworx bugs. From my point of view it should be an intrinsic interest of PTC itself to keep track of the bugs or best case fix it, without relying on customer support cases.

 

Thank you

wcui
16-Pearl
(To:BennyB)

@BP_9999767 I opened a support case for this issue. Once there is any update I will share here.

BP_9999767
4-Participant
(To:wcui)

This bug is known, PTC said it would not be fixed.

Announcements


Top Tags