A set of functions for working with dictionaries.
Dictionary
This function has 5 signatures:
- Dictionary([name1, value1, ..., nameN, valueN]?) -> Dictionary
- Dictionary(jsonText) -> Dictionary
- Dictionary(inputGeometry) -> Dictionary
- Dictionary(inputFeature) -> Dictionary
- Dictionary(inputDictionary, deep?) -> 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.field2
Dictionary(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 200
Dictionary(inputGeometry) -> Dictionary
Function bundle: Geometry
Converts a geometry value to a dictionary.
Parameter
- inputGeometry: Geometry - The geometry to convert to an Arcade dictionary.
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 references
Create 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 references
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 true
Converts text to a number
fromJSON("731.1")
// returns 731.1
Converts text to a dictionary
var d = fromJSON('{"kids": 3, "adults": 4 }')
d.kids + d.adults
// returns 7
Converts text to an array
fromJSON('["one", 2, "three", false]')
// returns [ "one", 2, "three", false ]
Converts text to null
fromJSON("null")
// returns null
HasKey
HasKey(value, key) -> Boolean
Function bundle: Core
Indicates whether a dictionary or feature has the input key.
Parameters
- value: Dictionary | Feature - The dictionary or feature to check for a key or field name.
- key: Text - The key or field name to check.
Return value: Boolean
Example
prints true
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
HasKey(d, 'Cobourg');
HasValue
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 | Feature - The dictionary or feature 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 true
Dictionary with key that does not have a value
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', null);
HasValue(d, 'Cobourg');
// returns false
Dictionary without the provided key
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000');
HasValue(d, 'Cobourg');
// returns false
Dictionary without the provided key
if ( HasValue( Schema($feature).fields[0], "domain" ) ) {
// Do something with the value if true
}