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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Set json key with a variable

JO_9930585
10-Marble

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