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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Set json key with a variable

JO_9930585
9-Granite

Set json key with a variable

In standard javascript one would simply do this..

 

 

 

let key = "somthing"
let jsonObject = {[key]: "value"}

 

 

 

But Thingworx doesn't allow this. How can I set a key using a variable in thingworx?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

let jsonObject= {}
userInput[key] = "value"

View solution in original post

2 REPLIES 2

let jsonObject= {}
userInput[key] = "value"

jensc
17-Peridot
(To:JO_9930585)

Hello,

 

The code you have given doesn't seem to include all of the information needed as "userInput" and "key" are undefined.

Here is a complete code showing how you can use a variable for the key value of a JSON:

let jsonObject = {};
let key = "myKey";
let value = "myValue";

jsonObject[key] = value;

  

Regards,

Jens

Top Tags