AnsweredAssumed Answered

JSONSetElement - conditional switch between JSONString and JSONNull

Question asked by fmdataweb on May 19, 2018
Latest reply on May 23, 2018 by Paul Jansen


I'm creating some JSON data in a calculation using the Let function as follows:

 

Let([

 

~json = JSONSetElement ( "" ;

 

["id"; CustomerData::ID; JSONNumber ];

["name"; CustomerData::Name; JSONString ];

["value"; CustomerData::Value; JSONString ] )

];

 

JSONSetElement( $customer_data ; $counter ; ~json ; JSONObject )

)

 

I now need to change the value line to use JSONString as the type if there is a value and JSONNull if that field is empty. I've tried to use the Case function to do this here but I'm getting an error when I click OK on my calculation.

 

The Case statement would be like this:

 

Case (

IsEmpty ( CustomerData::Value ) ; ["value"; CustomerData::Value; JSONNull ] ;

["value"; CustomerData::Value; JSONString ]

)

 

Anyone able to show me the correct syntax to incorporate this Case statement into the Let function, or if there's a better way that's fine as well.

Outcomes