TeraScript JSON Utilities

Filename: JSONutils.tcf

Class: JSONutils

Release: May 2, 2016

Method 1: arrayToJSON

Returns: Text (JSON)
Parameter 1: Array 

Description: This method formats each row in a TeraScript array into a JSON object. 
Returns a JSON array (comma-delimited string) of JSON objects or, if the input array has a single row, a single JSON object. If the input array is empty, returns an empty JSON object. 
Each row is formatted into a JSON object with the column names as keys and the column values as the string values. If any column name is empty, it is set to the value "Column #" where # is the index of the column. It is recommended to assign row zero of the array to the desired key names before passing it in. All strings are double quoted and special characters are escaped. 

Method 2: parseJSON

Returns: Text
Parameter 1: Text (JSON)
Parameter 2: Text or Array (out only)

Description: This method parses a JSON string into a TeraScript array or text.  
Returns the type of the JSON string (number, string, value object or array) and the resulting TeraScript array or text.
When the input is a JSON number, string or keyword value ("true", "false", or "null") this method will return "number", "string", or "value", respectively, as the type and the properly decoded value in the out parameter. When a JSON string is parsed, the Unicode escape sequence (\u4HEX) will return the same Unicode character in HTML encoding (&#x4HEX;).
When the input is a JSON object, this method will return "object" as the type and output a TeraScript array with one row and as many columns as pairs in the object.
The name of each column, row zero, will be assigned the key and the cell will contain a JSON formatted string of the value to be passed back into this method for further processing.
When the input is a JSON array this method will return "array" as the type and output a single-column TeraScript array with one row for each item in the JSON array. Row zero will not have a name and each cell in the first column will contain a JSON formatted string to be passed back into this method for further processing.


Method 3: parseFlatObject

Returns: Array
Parameter 1: Text (JSON)

Description: This is a convenience method that uses the parseJSON method to parse a JSON formatted string into a TeraScript array in the special case when the JSON string is an object and all of the values of the pairs are strings, numbers, or keywords. In other words, there are no nested arrays or objects, it is flat. The returned array has the same format as parseJSON, that is, it has a single row and one column per each pair in the object. Row zero contains the key and row one contains the value. Unlike parseJSON, the pair values are already parsed and ready to use.

Method 4: parseFlatArray

Returns: Array
Parameter 1: Text (JSON)

Description: This is a convenience method that uses the parseJSON method to parse a JSON formatted string into a TeraScript array in the special case when the JSON string is an array and all of the values of the array are strings, numbers, or keywords. In other words, there are no nested arrays or objects, it is flat. The returned array has the same format as parseJSON, that is, it has a single column and one row for each value in the array. Unlike parseJSON, the values are already parsed and ready to use.