Skip to main content
16-Pearl
June 7, 2022
Solved

Updating thing properties with JSON values

  • June 7, 2022
  • 1 reply
  • 1299 views

Hi, there

 

I have converted my JSON object to string (by means of the .parse) so that I could split the values. 

Now I want to update my thing properties with the values from my JSON object.

This JSON object and the thing properties are all on one thing.

 

I only managed to update the value at [0] index. When I try index [1] or higher, it throws an error.

Could you direct me if this issue has been solved already or any suggestions on how to achieve the updating of thing properties with the respective json values?

 

Much appreciated.

 

Best answer by abjain

@Janicen : Please go through the documentation for working in json objects.

https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Best_Practices_for_Developing_Applications/workingwithjsonobjects.html

 

So , lets suppose if you have json stored on a property 'propjson' on your thing, then you can extract a value from the json using its 'key' and store it on a property defined on your thing. Eg.

var json = me.propjson;
me.newval=json['dataChangeType'] ;

1 reply

abjain15-MoonstoneAnswer
15-Moonstone
June 8, 2022

@Janicen : Please go through the documentation for working in json objects.

https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Best_Practices_for_Developing_Applications/workingwithjsonobjects.html

 

So , lets suppose if you have json stored on a property 'propjson' on your thing, then you can extract a value from the json using its 'key' and store it on a property defined on your thing. Eg.

var json = me.propjson;
me.newval=json['dataChangeType'] ;