This component containing JavaScript utilities to be used in intermediate to advanced scenarios, such as safe JSON string parsing.
(Function) CorrectJSONStringForParse
Strips a JSON object string of whitespaces, wraps keys in double-quotes and replaces any occurrences of single-quotes to double quotes, in order to make it compatible with JSON.parse. Based off of https://stackoverflow.com/a/26291352/1293116
Inputs
JSONString
Type: Text. Mandatory. JSON String to be corrected.
Outputs
CorrectedJSONString
Type: Text. Result of correction from JSONString.
Example
JSON String: { hello: 'world', places: ['Africa', 'America', 'Asia', 'Australia'] }
CorrectedJSONString:: { "hello": "world", "places": ["Africa", "America", "Asia", "Australia"] }
(Function) ReplaceObjectTaggedAttributes
Replaces constant attributes in a JSON object that are wrapped with the Delimiter text. Uses the RootObjectFunction parameter function to obtain values or, if none is provided, uses JavaScript's 'eval'.
JSONObject
Type: Object. Mandatory.
Delimiter
Type: Text. Mandatory.
RootObjectFunction
ReplacedJSONObject
Type: Object.
(Function) SafelyEvalStringIntoObject
Does a safe 'eval' of the given string through a switch-case mapping. The first value in the string (the root) will be obtained using the RootObjectFunction. If a complete mapping is not defined for variable, it will return a 'null' object.
ConstantString
Function object that will be used to return the first value in the string (the root). This must value must be assigned to an "Object" output parameter.
Object
(Function) TagConstantsInJSONString
Takes a JSON string, identifies possible constants and wraps them in double quotes and the '§' character to be easily identifiable.
ConstantPreffix
TaggedJSONString
Type: Text.
(Function) TransformConstantsInJSONString
Takes a JSON string, identifies possible constants and applies a transformation to them, according to a given function. NOTE: The given function MUST assign an output parameter named 'Object'. It may have other outputs, but this one contains the value of the intended transformation.
TransformationFunction
TransformedJSONString
Correct JSON String for parse
Strips a JSON object string of whitespaces, wraps keys in double-quotes and replaces any occurrences of single-quotes to double quotes, in order to make it compatible with JSON.parse.
Input parameters
Invalid JSON string to be corrected
Output parameters
The corrected JSON string
Usage
Correct JSON String for parse with Eval
Attempts to correct an invalid JSON string with JavaScript's 'eval' function.
IMPORTANT: Eval() is a JS function that executes javascript from a string and is an enormous security risk.
Avoid using this action if you can and if not, then only use it if the JSON String to correct is from a trusted source. Use with caution.
RemoveParentheses
Should parentheses() be removed? This can avoid some code injection on the 'eval' function but can break your JSON string.
Replace attributes in a JSON object
Replaces constant attributes in a JSON object that are wrapped with the Delimiter text.Uses the RootObjectFunction parameter function to obtain values or, if none is provided, uses JavaScript's 'eval'.
Avoid leaving the RootObjectFunction parameter empty if you can.
JSON Object where the tagged attributes will be replaced
Characters used to identify the constants that are wrapped in this same characters
Function where the values will be replaced at.
JSON Object with the values replaced
Safe eval of string into object
Does a safe 'eval' of the given string through a switch-case mapping. The first value in the string (the root) will be obtained using the RootObjectFunction.If a complete mapping is not defined for a variable, it will return a 'null' object.
Constant string to be evaluated.
Function object that will be used to return the first value in the string (the root). This value must be assigned to an "Object" output parameter.
Evaluated JSON object
Tag constant in a JSON string
Takes a JSON string, identifies possible constants and wraps them in double quotes and the Delimiter character to be easily identifiable.
JSON string to be tagged
ConstantPrefix
String used to search for constants
Character/s to wrap the found constants
The input JSON string with its constants tagged
Transform constant in JSON string
Takes a JSON string, identifies possible constants and applies a transformation to them, according to a given function.NOTE: The given function MUST assign an output parameter named 'Object'. It may have other outputs, but this one contains the value of the intended transformation.
JSON string where the constants are going to get transformed
Function used to replace the constants found
The input JSON string with its constants transformed