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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Set json key with a variable

JO_9930585
12-Amethyst

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?

 

 

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

Announcements


Top Tags