Skip to main content
14-Alexandrite
May 25, 2023
Solved

Set json key with a variable

  • May 25, 2023
  • 1 reply
  • 5181 views

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?

 

 

Best answer by JO_9930585

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

1 reply

JO_993058514-AlexandriteAuthorAnswer
14-Alexandrite
May 25, 2023

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

17-Peridot
May 26, 2023

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