getstructurevalue(
STRUCTURE
,
INDEX
)
The getstructurevalue( function extracts a value from a structure of nested Data Dictionaries and/or Data Arrays.
Parameters
This function has two parameters:
structure – a structured collection of data. This must be a data dictionary or data array, which may contain nested dictionaries or arrays.
index – is the desired index into the collection. For data dictionaries the index must be text, for data arrays it must be an integer. This parameter can be repeated to access multiple levels of the structure.
Description
This function extracts a value from a structure of nested Data Dictionaries and/or Data Arrays. You can use this function in lieu of multiple nested getdictionaryvalue( and array( functions.
For example, supposed you have a variable named people that contains a data array of different people. Each element of this array contains a dictionary with different attributes for each person (name, address, etc.). One of these attributes is a data array of each person’s children. With this formula, you could find the name of the second child of the 4th person.
array(getdictionaryvalue(array(people,4),"Children"),2)
That’s a rather contorted formula. We can make it much simpler by using the getstructurevalue( function instead.
getstructurevalue(people,4,"Children",2)
In this example the structured data in people has three levels. There is an index parameter for each level of the structure. If the level is an array, the corresponding index parameter must be an integer. If the level is a dictionary, the corresponding index parameter must be text (the name of the desired element).
The getstructurevalue( function is ideal for working with JSON data that has been converted into a Panorama variable with the jsonimport( function. The code below will construct a people variable along the lines discussed above.
let people = jsonimport(|||
[
{"Name" : "Jack", "Color" : "Blue", "Size" : 38, "Children" : ["Mary", "Ellen", "Mark"]},
{"Name" : "Mary", "Color" : "Red", "Size" : 29, "Children" : ["Wayne"]},
{"Name" : "Bob", "Color" : "Orange", "Size" : 31, "Children" : ["Bill", "Tom"]}
{"Name" : "Eric", "Color" : "Yellow", "Size" : 40, "Children" : ["Jeff", "Ryan"]},
{"Name" : "Rita", "Color" : "Blue", "Size" : 24, "Children" : ["Matthew"]},
]
|||)
The getstructurevalue( function can be used to extract various components of this structured data.
getstructurevalue(people,4,"Children",2) ☞ Ryan
getstructurevalue(people,2,"Name") ☞ Mary
getstructurevalue(people,3,"Size") ☞ 31
You don’t have to include an index for every level of the structure. If you omit one or more levels, the function will return a structure, in this case an array.
arraysize(getstructurevalue(people,3,"Children")) ☞ 2
exportdataarray(getstructurevalue(people,3,"Children"),", ") ☞ Bill, Tom
If you specify an element that doesn’t exist, the getstructurevalue( function will return an error. Use the catcherror( function if you want to ignore the error.
See Also
- appenddataarrays( -- appends two or more data arrays to each other (see Data Arrays).
- appenddictionaryvalue -- appends a value to an item in a dictionary (see Data Dictionaries).
- array( -- extracts a single data item from a text array or a data array (see Text Arrays and Data Arrays).
- arrayboth -- creates a new array from two existing arrays. The new array contains only items that are in both of the original arrays.
- arrayboth( -- creates a new array from two arrays. The new array contains only items that are in both of the original arrays.
- arraybuild -- builds an array by scanning a database and creating an array element for every record (including invisible records) in the database (see Text Arrays).
- arraybuild( -- builds an array by scanning a database and creating an array element for every record (including invisible records) in the database (see Text Arrays).
- arraychange( -- changes the value of a single data item in a text array or a data array (see Text Arrays and Data Arrays).
- arraycolumn( -- extracts a column from a two dimensional array.
- arraycontains( -- checks to see if any element of a text array or a data array matches a specified value.
- arraydeduplicate( -- removes duplicate elements from a text array (see Text Arrays).
- arraydelete( -- deletes (removes) one or more elements from a text array or a data array (see Text Arrays and Data Arrays).
- arraydeletevalue( -- deletes any array elements that match the value parameter. This must be an exact match, including upper and lower case. If the value occurs multiple times in the array, every occurence of the value will be removed, with one exception: if the value occurs in two consecutive array elements, only the first occurence will be deleted.
- arraydifference -- creates a new array from two existing text arrays. The new array contains only items that are in the first array but *not* in the second array.
- arraydifference( -- creates a new array from two existing text arrays. The new array contains only items that are in the first array but *not* in the second array.
- arrayelement( -- converts between character positions and array element numbers in a text array.
- arrayfilter( -- processes each element of a text array or a data array with a formula (see Text Arrays and Data Arrays).
- arrayfirst( -- extracts the first element of a text array.
- arrayhack( -- hacks an array by adding, replacing or removing array elements
- arrayinsert( -- inserts one or more empty elements into the middle of a text array (see [Text Arrays]).
- arrayitemsandwich( -- adds a prefix and/or suffix to each non-blank item in a text array.
- arrayitemtrim( -- removes characters from the beginning and/or end of each item in an array.
- arraylast( -- extracts the last element of an array.
- arraylefttrim( -- removes one or more elements from the beginning of an array.
- arraylookup( -- uses a key to look up a value in a two dimensional text array containing key/value pairs (see Text Arrays).
- arraymerge( -- merges two text arrays together (see [Text Arrays]).
- arraymultisort -- sorts a two-dimensional array on the key of one or more of its columns.
- arraymultisort( -- sorts a two-dimensional array on the key of one or more of its columns.
- arraynotcontains( -- is the reverse of arraycontains(. it returns *false* if the value is in the array, *true* if it is not in the array.
- arraynumericsort( -- sorts a text array in numeric order (see Text Arrays).
- arraynumerictotal -- totals all the numeric elements of a text array.
- arraynumerictotal( -- totals all the numeric elements of a text array.
- arrayrandomize -- reorders an array in random order.
- arrayrandomize( -- reorders an array in random order.
- arrayrange( -- extracts a series of data items from a text array or a data array (see Text Arrays and Data Arrays).
- arrayrelocate -- moves one or more items in a text array to a new position.
- arrayrelocate( -- moves one or more items to a new position in a text array or a data array (see Text Arrays and Data Arrays).
- arrayreplacevalue( -- changes array elements that match a specified value.
- arrayreverse( -- reverses the order of the elements in a text array or a data array (see Text Arrays and Data Arrays).
- arrayreverselookup( -- uses a value to look up a key in a two dimensional text array containing key/value pairs (see Text Arrays).
- arraysearch( -- searches a text array or a data array (see Text Arrays and Data Arrays) to see if it contains a specific value.
- arrayselectedbuild -- builds an array by scanning a database and creating an array element for every visible (selected) record in the database (see Text Arrays).
- arrayselectedbuild( -- builds an array by scanning a database and creating an array element for every visible (selected) record in the database (see Text Arrays).
- arraysize( -- returns the number of elements in a text array or a data array (see Text Arrays and Data Arrays).
- arraysort -- sorts the elements in an array (see Text Arrays).
- arraysort( -- alphabetizes (A-Z) the elements in a text array (see [Text Arrays]).
- arraystrip -- strips blank elements from an array.
- arraystrip( -- removes any blank elements from a text array or a data array (see Text Arrays and Data Arrays).
- arraytableceiling( -- looks up a value in a double column table, similar to the table( function but from an array instead of a database.
- arraytablefloor( -- looks up a value in a double column table, similar to the table( function but from an array instead of a database.
- arraytoggle -- "toggles" a value within an array.
- arraytopythonlist( -- converts a Panorama array into a Python list.
- arraytrim( -- removes one or more elements from the end of an array.
- arrayunpropagate -- scans an array from top to bottom, removing duplicate values in a row.
- arrayunpropagate( -- scans an array from top to bottom, removing duplicate values in a row.
- changedictionaryname -- changes the name (key) of an item in a dictionary (see Data Dictionaries).
- changedictionaryvalues( -- changes one or more values in a dictionary (see Data Dictionaries).
- chararray( -- extracts a single character from text.
- classicdictionaryvalue( -- returns the value of an item in the dictionary, given its key (see Data Dictionaries). Unlike getdictionaryvalue(, this function does not treat keys as case sensitive.
- clearglobaldictionaryvalues -- clears (removes) all the keys and values from the specified global dictionary.
- commalist( -- converts a text array (see Text Arrays) into an English list, with items separated by a comma and a space, except for the last two items which are separated by the word *and* and spaces.
- commatocr( -- converts a comma delimited array into a carriage return delimited array.
- copypartialdictionary -- builds a new dictionary and initializes it with values from an existing dictionary (see Data Dictionaries).
- copypartialdictionary( -- partially copies a dictionary (see Data Dictionaries).
- csvtotsv( -- converts comma separated text into tab separated text.
- Data Arrays -- A numbered collection of data values.
- Data Dictionaries -- Overview of Panorama's key/value data dictionaries.
- dataarray( -- creates a data array from zero or more separate values (see Data Arrays).
- dataarrayappend( -- appends one or more values to the end of an existing array.
- dataarraybuild( -- builds a data array by scanning a database and creating an array element for every record (including invisible records) in the database (see Data Arrays).
- dataarrayinsert( -- inserts one or more values into the middle of an existing array.
- dataarrayselectedbuild( -- builds a data array by scanning a database and creating an array element for every visible record in the database (see Data Arrays).
- deletedictionaryvalue -- deletes a key/value pair from a dictionary (see Data Dictionaries).
- deletedictionaryvalue( -- deletes one or more key/value pairs from a dictionary (see Data Dictionaries).
- deleteglobaldictionaryvalues -- deletes one or more global dictionary values.
- dictionaryassignmentscode( -- returns code that can be used to take the values in a dictionary (see Data Dictionaries) and assign them to fields or variables based on the dictionary keys.
- dictionarydifference -- builds an array that lists keys of dictionary values that are different between two dictionaries (see Data Dictionaries).
- dictionaryfromarray( -- builds a new dictionary and initializes it from a two dimensional text array (see Data Dictionaries and Text Arrays).
- dictionaryfromvariables( -- builds a new dictionary and initializes it from a list of variables (carriage return delimited).
- dictionaryvalueexists -- returns true or false depending on whether or not a key/value pair exists in a dictionary (see Data Dictionaries).
- dictionaryvalueexists( -- returns true or false depending on whether or not a key/value pair exists in a dictionary (see Data Dictionaries).
- dumpdictionary -- returns a carriage return separated array of dictionary keys and values (see Data Dictionaries).
- dumpdictionary( -- returns a carriage return separated array of dictionary keys and values (see Data Dictionaries).
- dumpdictionaryquoted -- returns a carriage return separated array of dictionary keys and values (see Data Dictionaries).
- dumpdictionaryquoted( -- returns a carriage return separated array of dictionary keys and values (see Data Dictionaries). The text values are quoted.
- dumpdictionarysource( -- returns a carriage return separated array of dictionary keys and values (see Data Dictionaries). The keys and values are quoted so that they could be used to re-assemble the dictionary with the initializedictionary( function.
- exportdataarray( -- converts a data array into a text array (see Data Arrays and Text Arrays).
- extract( -- extracts a single data item from a text array, and can also be used to count the number of items in the array.
- generatedataarray( -- generates a new data array based on a formula (see Data Arrays and Text Arrays).
- getdictionarykey -- returns the key of an item in the dictionary, given its value. This is essentially the opposite of the getdictionaryvalue( function (see Data Dictionaries).
- getdictionarykey( -- returns the key of an item in the dictionary, given its value). This is essentially the opposite of the getdictionaryvalue( function (see Data Dictionaries).
- getdictionaryvalue -- returns the value of an item in the dictionary, given its key (see Data Dictionaries).
- getdictionaryvalue( -- returns the value of an item in the dictionary, given its key (see Data Dictionaries).
- getglobaldictionary( -- converts a global dictionary into a regular dictionary.
- Global Dictionaries -- alertnate high performance method to store multiple data items, much faster than regular data dictionaries.
- globaldictionarybuild -- builds a global dictionary by scanning a database.
- globaldictionarykeys( -- returns a cr()-separated array containing the keys in a global dictionary, or the names of all global dictionaries.
- globaldictionaryvalue( -- returns the value of an item in a global dictionary, given its key (see Global Dictionaries).
- htmlarraytable -- generates an HTML table from an arrray.
- htmldatamerge -- uses a template to generate HTML you want from a database.
- htmldatatable -- generates an HTML table from selected data in the current database.
- htmltabletoarray -- converts an HTML table into a text array.
- importdataarray( -- converts a text array into a data array (see Data Arrays and Text Arrays).
- info("timerinfo") -- returns a dictionary that contains all of the properties of the currently running timer.
- initializedictionary -- builds a new dictionary and initializes it with one or more key/value entries (see Data Dictionaries).
- initializedictionary( -- builds a new dictionary and initializes it with zero or more key/value entries (see Data Dictionaries).
- initializedictionaryvalue( -- builds a new dictionary and initializes it with one or more entries (see Data Dictionaries). This function is deprecated, we recommend using the initializedictionary( function instead.
- lineitemarray( -- converts the data in a set of line item fields into a text array (see Text Arrays).
- linescontain( -- checks to see if any line in a carriage return separated array matches the specified value.
- linesnotcontain( -- is the reverse of the linescontain( function.
- linesort( -- sorts lines of text in ascending order.
- linestrip( -- removes any blank lines from the text.
- listdictionarykeys( -- returns a list of the keys in a dictionary collection.
- listdictionarynames -- returns a list of the names (keys) in a dictionary (see Data Dictionaries).
- makenumberedarray -- generates a numeric sequenced text array.
- makenumberedarray( -- generates a numeric sequenced text array.
- mergedictionaries -- merges the contents of two or more dictionaries (see Data Dictionaries).
- mergedictionaries( -- merges the contents of two or more dictionaries (see Data Dictionaries).
- randomarrayelement( -- returns a random element from an array.
- randomline( -- returns a random line from multiple lines of text.
- randomword( -- returns a random word from a list of words.
- renamedictionarykey( -- changes the key (name) of one or more values in a dictionary (see Data Dictionaries).
- setdictionaryvalue -- changes a value in a dictionary (see Data Dictionaries).
- setfieldproperties -- modifies one or more properties (name, data type, formula, etc.) of the current field.
- setglobaldictionaryvalues -- sets one or more key/value pairs in a global dictionary.
- setlocalsfromdictionary -- converts a dictionary into a collection of local variables. The names and values of the local variables will be derived from the dictionary contents.
- soundinfo( -- returns a dictionary that contains all of the properties of a sound.
- superarraybuild -- scans a database to create a text array. This statement is is similar to arraybuild, but with a number of additional options (see Text Arrays).
- tabarray( -- extracts the nth element from a tab delimited array.
- tagarray( -- builds an array (see Text Arrays) containing the body of all the specified tags (usually HTML tags) in the text.
- Text Arrays -- A numbered collection of text values.
- timerinfo( -- returns a dictionary that contains all of the properties of a timer.
- tsvtocsv( -- converts tab separated text into comma separated text.
- tsvtojson( -- converts tab separated text into JSON formatted text.
History
10.2 | New | New in this version. |