Miscellaneous functions

This page describes the additional set of predefined Jsonnet functions for the Data Transformer Script task available in Application Integration.

Before you begin

To use the following predefined functions, you must import the functions library in your script. Importing the functions library lets you use both the standard Jsonnet functions and the predefined Data Transformer functions.

Application Integration supports Jsonnet functions library v0.20.0. For information about the Jsonnet standard functions, see Jsonnet Standard Library.

Type

Syntax
type(value)
      
DescriptionIdentifies the data type of the input value.
Input parametervalue: The input value. This can be a string, boolean, integer, object, or function.
Return typeSTRING
OutputReturns a string indicating the data type of the input value.

Length

    Syntax
    length(value)
          
    DescriptionCalculates the length of the input value.
    Input parametervalue: The input value. This can be a string, array, or object.
    Return typeINTEGER
    OutputReturns the length of the input value based on its data type. Throws an error if the data type is not supported.

    Get

    Syntax
    get(object, field, default, includeHidden)
          
    DescriptionRetrieves the value of a specified field from an object.
    Input parameter
    • object: The input JSON object.
    • field: The name of the field to retrieve.
    • default: The default value to return if the field does not exist.
    • includeHidden: A boolean indicating whether to include hidden fields in the search.
    Return typeThe data type of the object field, or the data type of the default value if the field does not exist.
    OutputReturns the value of the specified field from the input object. If the field is not present, it returns the default value.

    Has

    Syntax
    has(object, field)
          
    DescriptionChecks if a specified field exists in an object.
    Input parameter
    • object: The input JSON object.
    • field: The name of the field to check for existence.
    Return typeBOOLEAN
    OutputReturns true if the given object has the specified field; otherwise, returns false.

    Object Fields

    Syntax
    objectFields(object)
          
    DescriptionExtracts the names of all fields from an object.
    Input parameterobject: The input JSON object.
    Return typeARRAY
    OutputReturns an array containing the names of all fields specified in the input object.

    Object Values

    Syntax
    objectValues(object)
          
    DescriptionExtracts the values of all fields from an object.
    Input parameterobject: The input JSON object.
    Return typeARRAY
    OutputReturns an array containing all the values of fields specified in the input object.

    Object Keys Values

    Syntax
    objectKeysValues(object)
          
    DescriptionExtracts all fields of the input object and organizes them into an array, with each element containing a key-value pair.
    Input parameterobject: The input JSON object.
    Return typeARRAY
    OutputReturns an array of objects from the input object, where each object has two fields: key (STRING) and value (OBJECT). The output does not include hidden fields.

    Prune

    Syntax
    prune(data)
          
    DescriptionRemoves all empty members of the data. "Empty" is defined as zero length or null.
    Input parameterdata: The input data to be pruned, which can be a string, object, or array.
    Return typeOBJECT/ARRAY/STRING
    OutputReturns the input data with all empty members (zero length or null) removed.

    Map with Key

    Syntax
    mapWithKey(function, object)
          
    DescriptionTransforms each key-value pair in the input object using the specified function. For example, if the specified function is concat, the result is a new object where each key-value pair is transformed such that the value becomes a concatenation of the key and value ({key: "value"} becomes {key: "key:value"}).
    Input parameter
    • function: The function that transforms each key-value pair.
    • object: The input JSON object to transform.
    Return typeOBJECT
    OutputReturns a new object with each key-value pair transformed according to the provided function.

    Function Expression

    Syntax
    functionExpression()
          
    DescriptionEditor for Jsonnet expressions, designed for medium or advanced operations, specifically for expression-type operations.
    Input parameterNot applicable (N/A)
    Return typeN/A
    OutputProvides an editor interface for creating advanced Jsonnet expressions.

    Is Null

    Syntax
    isNull(value)
          
    DescriptionChecks if the given value is null and returns a boolean indicating the result.
    Input parametervalue: The input value of any data type to be checked for null.
    Return typeBOOLEAN
    OutputReturns true if the value is null; otherwise, returns false.

    Recommendation