AnsweredAssumed Answered

JSONSetElement - Conditionally Add Element

Question asked by fmdataweb on Apr 28, 2018
Latest reply on May 1, 2018 by fmpdude

I'm using the JSONSetElement function and need to conditionally add an element if a field has a value in it. The JSON I'm trying to create will look like this:

 

{

"id" : 52415,

"qty" : 8,

"name" : "Rubber Tyres",

"category" : "Car Tyres"

}

 

and the calc currently looks like this:

 

JSONFormatElements (

JSONSetElement ( "" ;

["id" ; ProductID; JSONNumber];

["name" ; Name ; JSONString];

["qty" ; StockQTY; JSONNumber] ;

["category" ; ProductCategory ; JSONString]

)

)

 

I only need to include the:

 

["id" ; ProductID; JSONNumber];

 

if the ProductID has a value in it, but I can't work out the syntax to conditionally include elements when constructing my JSON. Appreciate any tips here on how to achieve this.

Outcomes