Handling json nulls [solved]

Dear all

I’m sure I’ve seen this before, but can’t find a solution this time…

<cfset str = "[[1234,1.2345],[5678,null]]">
<cfset xx = deserializejson(str)>
<cfdump var="#xx#">
<cfoutput>
	1.len #arraylen(xx[1])#<br/>
	1.1 #xx[1][1]#<br/>
	1.2 #xx[1][2]#<br/>
	2.len #arraylen(xx[2])#<br/>
	2.1 #xx[2][1]#<br/>
	2.2 #xx[2][2]#<br/>
</cfoutput>

The dump shows 2.2 as empty:null
The output is as I would expect: 1.len and 2.len both are 2
The error occurs at 2.2 : Element at position [2] does not exist in list.

If this element doesn’t exist, then obviously isnull(xx[2][2]) or isempty(xx[2][2]) produce the same error.

So how can I detect that null? A try-catch seems a bit heavyweight.

Lucee 5.2.9.31

Thanks

Richard

@Richard_Meredith-Har, Could you please enable complete null support in admin under settings -->language/compiler → null support

1 Like

That’s it! Fixed.
Thankyou for your super rapid reply.
Richard

1 Like