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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Property: Switching JSON

MS_FLiX_HSD
7-Bedrock

Property: Switching JSON

Good morning Community!

 

I have set up a service with the input Colour.  The following picture shows the code inside the service. 

 

Bildschirmfoto 2021-11-22 um 10.45.12.png

As shown in the picture I want to send the TimeStamp (ts) first and followed by the Colour which came as input. 

 

The property-value then somehow is the following:

 

Bildschirmfoto 2021-11-22 um 10.45.40.png

 

Why does Thingworx cange the sequence so that there is the Colour first?

 

I need it in the other way, like programmed within the service. Can someone help me with that?

 

Yours faithfully,

Marius

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @MS_FLiX_HSD 

 

As we know, JSON is an unordered set of value pairs. But what i have noticed while trying your Use case is that it is sorting values in alphabetical order. So, In case you want your time to come before instead of "ts" name it let's say "wz" or anything which comes after "t" or you can also change type into "abc". 

For example, me.OrderProcess = {"ts":result, "abc": Colour}

 

Revert back if you still face any challenges.

 

Regards

Bhawna

View solution in original post

6 REPLIES 6
nmutter
14-Alexandrite
(To:MS_FLiX_HSD)

I cannot help you with your exact issue. What I would challenge is why you need to have it in the same order? In general a json objects attribute order does not matter as you can access the attribute you want with the attribute name (e.g. me.OrderProcess.type or me.OrderProcess.ts).

 

The json spec also does specify that a json object is an unordered object of key/value pairs - https://stackoverflow.com/a/4920304 

Unfortunately the factory awaits the payload in this order.

Hi @MS_FLiX_HSD 

 

As we know, JSON is an unordered set of value pairs. But what i have noticed while trying your Use case is that it is sorting values in alphabetical order. So, In case you want your time to come before instead of "ts" name it let's say "wz" or anything which comes after "t" or you can also change type into "abc". 

For example, me.OrderProcess = {"ts":result, "abc": Colour}

 

Revert back if you still face any challenges.

 

Regards

Bhawna

Thank you for this hint! I didn't recognize that its alphabetically. I'll try to change the names. 

nmutter
14-Alexandrite
(To:MS_FLiX_HSD)

I don't think it is alphabetical in any case as when I tested it was not.

e.g. I assigned me.jsonProperty = {"cc": "C","aa": "A","bb": "B"};

and it was saved in the same order.

 

But if you find a working combination good.

 

Otherwise you could also set the property as type string and build the needed format on your own. me.stringProperty = "{\"ts\":\"" + result + ".....}";

In my case it was not saved in the same order. Maybe Thingworx put the time stamp at the end. But it is working now for me. I guess a String would also be possible. Thank you for reviewing! 

Top Tags