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)
      
Description Identifies the data type of the input value.
Input parameter value: The input value. This can be a string, boolean, integer, object, or function.
Return type STRING
Output Returns a string indicating the data type of the input value.

Length

Syntax
length(value)
      
Description Calculates the length of the input value.
Input parameter value: The input value. This can be a string, array, or object.
Return type INTEGER
Output Returns 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)
      
Description Retrieves 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 type The data type of the object field, or the data type of the default value if the field does not exist.
Output Returns 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)
      
Description Checks 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 type BOOLEAN
Output Returns true if the given object has the specified field; otherwise, returns false.

Object Fields

Syntax
objectFields(object)
      
Description Extracts the names of all fields from an object.
Input parameter object: The input JSON object.
Return type ARRAY
Output Returns an array containing the names of all fields specified in the input object.

Object Values

Syntax
objectValues(object)
      
Description Extracts the values of all fields from an object.
Input parameter object: The input JSON object.
Return type ARRAY
Output Returns an array containing all the values of fields specified in the input object.

Object Keys Values

Syntax
objectKeysValues(object)
      
Description Extracts all fields of the input object and organizes them into an array, with each element containing a key-value pair.
Input parameter object: The input JSON object.
Return type ARRAY
Output Returns 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)
      
Description Removes all empty members of the data. "Empty" is defined as zero length or null.
Input parameter data: The input data to be pruned, which can be a string, object, or array.
Return type OBJECT/ARRAY/STRING
Output Returns the input data with all empty members (zero length or null) removed.

Map with Key

Syntax
mapWithKey(function, object)
      
Description Transforms 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 type OBJECT
Output Returns a new object with each key-value pair transformed according to the provided function.

Function Expression

Syntax
functionExpression()
      
Description Editor for Jsonnet expressions, designed for medium or advanced operations, specifically for expression-type operations.
Input parameter Not applicable (N/A)
Return type N/A
Output Provides an editor interface for creating advanced Jsonnet expressions.

Recommendation