Select to view content in your preferred language

Attribute Rule: Unexpected Null error when parsing dictionary

168
1
03-25-2026 05:42 AM
Radnod
by
New Contributor

Hi, 

I have trouble validating an attribute rule using a dictionary as source (using ArcGIS Pro 3.2.1).

My input is a JSON string (generated by another rule with priority 1):

{"Dataset1":[], "Dataset2": ["text", "more text"]}

 

I am using this expression to parse the JSON:

var out = null;
var dataset = "Dataset2";
var dict = FromJSON(Text($feature.json));

var arr = dict[dataset];

if (IIf(DefaultValue(arr, 0) == 0, false, true)) {
  out = Concatenate(arr, ", ");
}
return out

 

Using the expression in a popup works, as attribute rule the validation always fails at line 5:

Arcade Error, unexpected null

It seems like the dictionary isn't parsed properly as long as I try to use it in an attribute rule.

Returning the dictionary as out works, the validation then complains about dict not being a string.

Returning out = Text(dict) returns the initial JSON string.

 

What am I doing wrong here?

 

0 Kudos
1 Reply
Robert_LeClair
Esri Esteemed Contributor

In reviewing this item, I found that this expression might work better:

var out = null;
var dataset = "Dataset2";

// Parse JSON safely
var dict = FromJSON(Text($feature.json));

if (IsEmpty(dict)) {
return null;
}

// Check if key exists
if (!HasKey(dict, dataset)) {
return null;
}

var arr = dict[dataset];

// Ensure it's a valid array with values
if (!IsEmpty(arr) && Count(arr) > 0) {
out = Concatenate(arr, ", ");
}

return out;

Why this works better is the HasKey() prevents invalid dictionary access, the IsEmpty avoids null dereferencing, the Count() ensures you're not concatenating an empty array and it removes the DefaultValue(arr, 0) logic which is not reliable for arrays.  I don't have the data to test but think it will work.

0 Kudos