Validate JSON Hash Map Data

Highlighted
Level 2

Re: Validate JSON Has Map Data

So the first problem is if Clinic ID has no value, it's printing the variable in the email.

The second issue is if the value of clinicID doesn't exist, it's still printing the variable in my email (like the below)

$clinics.Map[$CID]["NME"]

 

So that is why I am saying the IF statements are not evaluating properly. I am testing with 3 emails, one covering each use case. Proper ID, Missing ID, and Wrong ID

Highlighted
Level 10 - Community Moderator

Re: Validate JSON Has Map Data

The output is exactly what you'd expect from the code you have. It's evaluating properly.

 

$reference.isEmpty() is null if $reference is null, because you can't check emptiness of non-String/Array values.

 

!$reference.isEmpty() is true if $reference is null, because the null is coerced to a Boolean when you use !.

 

 

Highlighted
Level 2

Re: Validate JSON Has Map Data

Ok that makes sense, so how do I check if it's null? Putting null I get an error.

Highlighted
Level 10 - Community Moderator

Re: Validate JSON Has Map Data

if $reference is null

$display.alt($reference,"").isEmpty() is true 

 

if $reference is ""

!$display.alt($reference,"").isEmpty() is false

 

if $reference is "Sandy"

!$display.alt($reference,"").isEmpty() is true 

 

Highlighted
Level 2

Re: Validate JSON Has Map Data

I'm sorry, I am really not getting how to check if the value is null, that's the part I have been stuck on for this entire post.

 

Doing this

if $reference is null

$display.alt($reference,"").isEmpty() is true 

 

Is always returning true for me, regardless of the value of "Reference",

#set( $NME = "Physiotherapy" )
#set( $CID = $lead.ClinicID )
#if( ${CID.isEmpty()} == 'false' && ${clinics.Map.containsKey($CID)} == 'true' && ${clinics.Map[$CID].containsKey("NME")} == 'true' )
   #set( $NME = $clinics.Map[$CID]["NME"] )
   <br>
   All statements validate to TRUE STRING<br>
#end
$CID

#if ( $display.alt($CID,"").isEmpty() )
	The clinic has a value
#end

 

Highlighted
Level 10 - Community Moderator

Re: Validate JSON Has Map Data

$display.alt() returns its 1st argument if the 1st argument is anything other than null.  Otherwise, it returns the 2nd argument. 

 

The method is designed to be a null coalescing function, like COALESCE in SQL.

 

It's not possible for $display.alt($reference,"").isEmpty() to return true if $reference is a non-empty String.

Highlighted
Level 2

Re: Validate JSON Has Map Data

So this still isn't working, it must mean that when that data doesn't exist it's something other then "null", how can we figure out what is going on?

 

It always returns true for me, it doesn't matter if there is a clinic ID or not, and the contains never prints even if it does exist. 

Highlighted
Level 2

Re: Validate JSON Has Map Data

If $lead.ClinicID ) does not have a value in marketo, I want to print an alternative instead, I have tried to check if it's null, true/ false, or an empty string, but none of them are working properly.

 

How do I check if CID has a value or not?

 

#set( $CID = ${lead.ClinicID} )
Highlighted
Level 10 - Community Moderator

Re: Validate JSON Has Map Data

#if( $lead.clinicId.isEmpty() )
clinicId is explicitly empty
#elseif( $display.alt($lead.clinicId,"").isEmpty() )
clinicId is null
#else
clinicId has a non-empty String value ${lead.clinicId}
#end
Highlighted
Level 2

Re: Validate JSON Has Map Data

No change:

 

  • $lead.clinicId has a value of 123456 (Based on data in field and what i print on the page)

    • Result clincID is null
  • $lead.clinicId has no value in the marketo field (Based on data in field and what i print on the page)
    • Result clincID is null

The exact Code I did, CID is printing either the numbers (123456) or nothing as expected.

#set( $CID = $convert.toString( ${lead.ClinicID} ) )
#if( ${CID.isEmpty()} == 'false' && ${clinics.Map.containsKey($CID)} == 'true' && ${clinics.Map[$CID].containsKey("NME")} == 'true' )
   #set( $NME = $clinics.Map[$CID]["NME"] )
   <br>
   All statements validate to TRUE STRING<br>
#end
$CID

Below is the content<br/>
#if( $lead.ClinicID.isEmpty() )
clinicId is explicitly empty
#elseif( $display.alt($lead.ClinicID,"").isEmpty() )
clinicId is null
#else
clinicId has a non-empty String value ${lead.ClinicID}
#end