A set of functions for working with dictionaries.
Count
Count(inputDictionary) -> Number
Function bundle: Core
Returns the number of entries in a dictionary.
Parameter
- inputDictionary: Dictionary - The input dictionary.
Return value: Number
Example
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
Count(d);
// returns 3DefaultValue
This function has 2 signatures:
- Since v1.26 - DefaultValue(inputDictionary, key, defaultValue) -> Any
- Since v1.0 - DefaultValue(inputDictionary, keys, defaultValue) -> Any
DefaultValue(inputDictionary, key, defaultValue) -> Any
Function bundle: Core
Returns a specified default value if a key in a dictionary does not exist or the value at the specified key is null or an empty text value.
Parameters
- inputDictionary: Dictionary | Attachment - The dictionary or attachment to check.
- key: Text - The key to check.
- defaultValue: Any - This value is returned if the key does not exist or the value at the specified key is
nullor an empty text value.
Return value: Any
Returns the value at the specified key if defined. Otherwise, returns the value specified in default.
Examples
DefaultValue returns a defined value
var data = {
time: Date(2024, 0, 24, 12),
weather: {
precipitation: {
type: "rain",
value: 0.4,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
DefaultValue(data, "time", "No time logged")
// value of data.time is defined, so it is returned
// returns Jan 24, 2024, 12:00:00 PM system timeDefaultValue returns a default if there is no value at the specified key.
var data = {
time: '',
weather: {
precipitation: {
type: "rain",
value: 0.4,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
DefaultValue(data, "time", "No time logged")
// value of data.time is empty, so the default is returned
// returns "No time logged"DefaultValue returns a default if the key does not exist.
var data = {
time: ''
}
DefaultValue(data, "conditions", "n/a")
// the conditions key does not exist, so the default is returned
// returns "n/a"DefaultValue(inputDictionary, keys, defaultValue) -> Any
Function bundle: Core
Returns a specified default value if at least one of the keys in a nested dictionary does not exist or the value at the specified key is null or an empty text value.
Parameters
- inputDictionary: Dictionary | Attachment - The dictionary or attachment to check.
- keys: Array<Number | Text> - An array of the keys or indexes to check in each level of the container's structure.
- defaultValue: Any - This value is returned if at least one of the keys or indices does not exist or the value at the specified key is
nullor an empty text value.
Return value: Any
Returns the value at the specified key or index if defined. Otherwise, returns the value specified in default.
Examples
DefaultValue returns a defined value
var data = {
time: Date(2024, 0, 24, 12),
weather: {
precipitation: {
type: "rain",
value: 0.4,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
DefaultValue(data, ["weather", "precipitation", "value"], "No time logged")
// value of data.weather.precipitation.value is defined, so it is returned
// returns 0.4DefaultValue returns a default if there is no value at the specified key.
var data = {
time: Date(2024, 0, 24, 12),
weather: {
precipitation: {
type: "rain",
value: null,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
DefaultValue(data, ["weather", "precipitation", "value"], 0)
// value of data.weather.precipitation.value is null, so the default is returned
// returns 0DefaultValue returns a default if the key does not exist.
var data = {
time: Date(2024, 0, 24, 12),
weather: {
precipitation: {
type: "rain",
value: null,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
DefaultValue(data, ["weather", "wind", "value"], "n/a")
// the data.weather.wind key does not exist, so the default is returned
// returns "n/a"Check null value in an array within a dictionary with key that exists
var data = {
time: Date(2024, 0, 24, 12),
interval: 1,
intervalUnit: "days",
weather: {
precipitation: {
type: "rain",
values: [0.4, 0, 0, null, 0.1, 0.8, 1],
unit: "inches"
},
temperature: {
values: [50, 50, 51, 52, 55, 49, 51],
unit: "f"
},
}
}
DefaultValue(data, ["weather", "precipitation", "values", 3], 0)
// the value data.weather.precipitation.values[3] is null, so the default is returned
// returns 0Dictionary
This function has 6 signatures:
- Since v1.0 - Dictionary([name1, value1, ..., nameN, valueN]?) -> Dictionary
- Since v1.8 - Dictionary(jsonText) -> Dictionary
- Since v1.23 - Dictionary(inputGeometry) -> Dictionary
- Since v1.23 - Dictionary(inputFeature) -> Dictionary
- Since v1.23 - Dictionary(inputDictionary, deep?) -> Dictionary
- Since v1.30 - Dictionary(inputVoxel) -> Dictionary
Dictionary([name1, value1, ..., nameN, valueN]?) -> Dictionary
Function bundle: Core
Returns a new dictionary based on the provided arguments. The arguments are name/value pairs. e.g. dictionary('field1',val,'field2',val2,...).
Parameter
- [name1, value1, ..., nameN, valueN] (Optional): Any - Ongoing name/value pairs.
Return value: Dictionary
Example
prints 3
var d = Dictionary('field1', 1, 'field2', 2)
return d.field1 + d.field2Dictionary(jsonText) -> Dictionary
Function bundle: Core
Deserializes JSON text as an Arcade Dictionary.
Parameter
- jsonText: Text - The JSON to convert to an Arcade dictionary. This must be serialized as a text value.
Return value: Dictionary
Example
Deserializes JSON as a Dictionary.
var extraInfo = '{"id": 1, "population": 200, "city": "Spencer, ID"}'
var spencerIDdata = Dictionary(extraInfo)
spencerIDdata.population // Returns 200Dictionary(inputGeometry) -> Dictionary
Function bundle: Geometry
Converts a geometry value to a dictionary.
Parameter
- inputGeometry: Geometry - The geometry to convert to an Arcade dictionary. Starting at version 1.25, Polygon or Polyline inputs may contain curve objects when executed in ArcGIS Pro and ArcGIS Maps SDKs for Native Apps.
Return value: Dictionary
Example
Update the x attribute of a point geometry.
// convert the $feature's geometry to a dictionary
if (TypeOf(Geometry($feature)) == "Point") {
var ptDict = Dictionary(Geometry($feature));
ptDict.x *= 2; // stretch horizontally
// create a new geometry from the updated dictionary
return Geometry(ptDict);
}Dictionary(inputFeature) -> Dictionary
Function bundle: Core
Converts a feature to a dictionary.
Parameter
- inputFeature: Feature - The feature to convert to an Arcade dictionary.
Return value: Dictionary
Example
Convert a feature to a dictionary
// convert $feature to a dictionary
var featureDict = Dictionary($feature);Dictionary(inputDictionary, deep?) -> Dictionary
Function bundle: Core
Creates either a shallow or deep copy of a dictionary.
Parameters
- inputDictionary: Dictionary - The dictionary to copy.
- deep (Optional): Boolean - If
true, creates a deep copy of the dictionary will be created, meaning the properties of the output dictionary will not share the same references as the input dictionary. Default value isfalse.
Return value: Dictionary
Examples
Create a shallow copy of a Dictionary
var inputDict = {
company: {
name: "Esri",
location: "Redlands, CA"
},
office: "M123"
};
var copiedDict = Dictionary(inputDict);
return inputDict.company == copiedDict.company
// returns true
// this is a shallow copy of the Dictionary, so the dictionaries share the same referencesCreate a deep copy of a Dictionary
var deepCopy = Dictionary(inputDict, true);
return inputDict.company == deepCopy.company
// returns false
// this is a deep copy of the Dictionary, so the dictionaries do NOT share the same referencesDictionary(inputVoxel) -> Dictionary
Function bundle: Core
Converts a voxel to a dictionary.
Parameter
- inputVoxel: Voxel - The voxel to convert to an Arcade dictionary.
Return value: Dictionary
Example
Convert a voxel to a dictionary
// convert $voxel to a dictionary
var voxelDict = Dictionary($voxel);Erase
Erase(inputDictionary, key) -> Null
Function bundle: Core
Removes a key-value pair from a dictionary.
Parameters
- inputDictionary: Dictionary - The input dictionary.
- key: Text - The key to remove.
Return value: Null
Example
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
Erase(d, 'Grafton');
return d;
// returns {'Port Hope': 16214, 'Cobourg': 18519};FromJSON
FromJSON(jsonText) -> Dictionary | Array<Any> | Text | Boolean | Number
Function bundle: Core
Deserializes JSON text into its equivalent Arcade data types.
Parameter
- jsonText: Text - The JSON text to deserialize to an Arcade data type.
Return value: Dictionary | Array<Any> | Text | Boolean | Number
Examples
Converts text to a boolean
FromJSON("true")
// Returns trueConverts text to a number
fromJSON("731.1")
// returns 731.1Converts text to a dictionary
var d = fromJSON('{"kids": 3, "adults": 4 }')
d.kids + d.adults
// returns 7Converts text to an array
fromJSON('["one", 2, "three", false]')
// returns [ "one", 2, "three", false ]Converts text to null
fromJSON("null")
// returns nullGetKeys
GetKeys(inputDictionary) -> Array<Text>
Function bundle: Core
Returns an array of all keys in the dictionary, sorted alphabetically.
Parameter
- inputDictionary: Dictionary - The dictionary to get keys from.
Example
Returns an array of keys from the dictionary, in alphabetical order.
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
GetKeys(d);
// returns ['Cobourg', 'Grafton', 'Port Hope']GetValues
GetValues(inputDictionary) -> Array<Any>
Function bundle: Core
Returns an array of all values in the dictionary, ordered to match the alphabetical sorting of their keys.
Parameter
- inputDictionary: Dictionary - The dictionary to get values from.
Example
returns [18519, '
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
return GetValues(d);HasKey
HasKey(inputDictionary, key) -> Boolean
Function bundle: Core
Indicates whether a dictionary has the input key.
Parameters
- inputDictionary: Dictionary - The dictionary to check for a key.
- key: Text - The key to check.
Return value: Boolean
Example
prints true
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
HasKey(d, 'Cobourg');HasValue
This function has 2 signatures:
- Since v1.20 - HasValue(inputDictionary, key) -> Boolean
- Since v1.26 - HasValue(inputDictionary, keys) -> Boolean
HasValue(inputDictionary, key) -> Boolean
Function bundle: Core
Indicates whether a dictionary has a given key and if that key has a value.
Parameters
- inputDictionary: Dictionary | Attachment - The dictionary or attachment to check.
- key: Text - The key or field name to check.
Return value: Boolean
Examples
Dictionary with key that has a value
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
HasValue(d, 'Cobourg');
// returns trueDictionary with key that does not have a value
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', null);
HasValue(d, 'Cobourg');
// returns falseDictionary without the provided key
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000');
HasValue(d, 'Cobourg');
// returns falseDictionary without the provided key
if ( HasValue( Schema($feature).fields[0], "domain" ) ) {
// Do something with the value if true
}HasValue(inputDictionary, keys) -> Boolean
Function bundle: Core
Checks whether a property nested several levels deep in a dictionary has a value. This allows you to drill into a nested structure in one step rather than check values at each level. Returns true if the keys and indexes at each level of the structure exist and include a non-null value.
Parameters
- inputDictionary: Dictionary | Attachment - The dictionary or attachment to check.
- keys: Array<Number | Text> - An array of the keys or indexes to check in each level of the structure.
Return value: Boolean
Examples
Check dictionary with key that has a nested value
var data = {
time: Date(2024, 0, 24, 12),
weather: {
precipitation: {
type: "rain",
value: 0.4,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
if(HasValue(data, ["weather","precipitation","value"])){
// if() evaluates to true, thus executing the return
return data.weather.precipitation.value;
}Check value in a dictionary with key that does not exist
var data = {
time: Date(2024, 0, 24, 12),
weather: {
precipitation: {
type: "rain",
value: 0.4,
unit: "inches"
},
temperature: {
value: 50,
unit: "f"
},
conditions: {
description: "Overcast"
}
}
}
if(HasValue(data, ["weather","precipitation","values", 0])){
// if() evaluates to false ("values" does not exist), thus avoiding the block
return data.weather.precipitation.values;
}Check value in an array within a dictionary with key that does exist
var data = {
time: Date(2024, 0, 24, 12),
interval: 1,
intervalUnit: "days",
weather: {
precipitation: {
type: "rain",
values: [0.4, 0, 0, null, 0.1, 0.8, 1],
unit: "inches"
},
temperature: {
values: [50, 50, 51, 52, 55, 49, 51],
unit: "f"
},
}
}
if(HasValue(data, ["weather","precipitation","values", 6])){
// if() evaluates to true, thus executing the return
return data.weather.precipitation.values[6];
}Insert
Insert(inputDictionary, key, value) -> Null
Function bundle: Core
Inserts a key-value pair into the dictionary. If the key already exists, its value will be updated.
Parameters
- inputDictionary: Dictionary - The input dictionary.
- key: Text - The key to insert.
- value: Any - The value to insert.
Return value: Null
Examples
Inserts a new key-value pair into a dictionary.
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
Insert(d, 'Colborne', 1474);
return d;
// returns {'Port Hope': 16214, 'Grafton': '<1000', 'Cobourg': 18519, 'Colborne': 1474}Updates the value for an existing key in a dictionary.
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
Insert(d, 'Grafton', 1200);
return d;
// returns {'Port Hope': 16214, 'Grafton': 1200, 'Cobourg': 18519}