Encode/Decode Functions

Each of the following functions will encode a string according the rules of the given data format.

escapeJson

Description: This function prepares the Subject to be inserted into JSON document by escaping the characters in the String using Json String rules. The function correctly escapes quotes and control-chars (tab, backslash, cr, ff, etc.)

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is 'He didn’t say, "Stop!"', then the Expression ${message:escapeJson()} will return 'He didn’t say, \"Stop!\"'

escapeXml

Description: This function prepares the Subject to be inserted into XML document by escaping the characters in a String using XML entities. The function correctly escapes quotes, apostrophe, ampersand, <, > and control-chars.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"bread" & "butter"', then the Expression ${message:escapeXml()} will return '"bread" & "butter"'

escapeCsv

Description: This function prepares the Subject to be inserted into CSV document by escaping the characters in a String using the rules in RFC 4180. The function correctly escapes quotes and surround the string in quotes if needed.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is 'But finally, she left', then the Expression ${message:escapeCsv()} will return '"But finally, she left"'

escapeHtml3

Description: This function prepares the Subject to be inserted into HTML document by escaping the characters in a String using the HTML entities. Supports only the HTML 3.0 entities.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"bread" & "butter"', then the Expression ${message:escapeHtml3()} will return '"bread" & "butter"'

escapeHtml4

Description: This function prepares the Subject to be inserted into HTML document by escaping the characters in a String using the HTML entities. Supports all known HTML 4.0 entities.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"bread" & "butter"', then the Expression ${message:escapeHtml4()} will return '"bread" & "butter"'

unescapeJson

Description: This function unescapes any Json literals found in the String.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is 'He didn’t say, \"Stop!\"', then the Expression ${message:unescapeJson()} will return 'He didn’t say, "Stop!"'

unescapeXml

Description: This function unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports only the five basic XML entities (gt, lt, quot, amp, apos).

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"bread" & "butter"', then the Expression ${message:unescapeXml()} will return '"bread" & "butter"'

unescapeCsv

Description: This function unescapes a String from a CSV document according to the rules of RFC 4180.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"But finally, she left"', then the Expression ${message:unescapeCsv()} will return 'But finally, she left'

unescapeHtml3

Description: This function unescapes a string containing HTML 3 entity to a string containing the actual Unicode characters corresponding to the escapes. Supports only HTML 3.0 entities.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"bread" & "butter"', then the Expression ${message:unescapeHtml3()} will return '"bread" & "butter"'

unescapeHtml4

Description: This function unescapes a string containing HTML 4 entity to a string containing the actual Unicode characters corresponding to the escapes. Supports all known HTML 4.0 entities.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If the "message" attribute is '"bread" & "butter"', then the Expression ${message:unescapeHtml4()} will return '"bread" & "butter"'

urlEncode

Description: Returns a URL-friendly version of the Subject. This is useful, for instance, when using an attribute value to indicate the URL of a website.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: We can URL-Encode an attribute named "url" by using the Expression ${url:urlEncode()}. If the value of the "url" attribute is "https://nifi.apache.org/some value with spaces", this Expression will then return "https%3A%2F%2Fnifi.apache.org%2Fsome+value+with+spaces".

urlDecode

Description: Converts a URL-friendly version of the Subject into a human-readable form.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If we have a URL-Encoded attribute named "url" with the value "https://nifi.apache.org/some%20value%20with%20spaces" or "https%3A%2F%2Fnifi.apache.org%2Fsome+value+with+spaces", then the Expression ${url:urlDecode()} will return "https://nifi.apache.org/some value with spaces".

base64Encode

Description: Returns a Base64 encoded string. This is useful for being able to transfer binary data as ascii.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: We can Base64-Encoded an attribute named "payload" by using the Expression ${payload:base64Encode()} If the attribute payload had a value of "admin:admin" then the Expression ${payload:base64Encode()} will return "YWRtaW46YWRtaW4=".

base64Decode

Description: Reverses the Base64 encoding on given string.

Subject Type: String

Arguments: No arguments

Return Type: String

Examples: If we have a Base64-Encoded attribute named "payload" with the value "YWRtaW46YWRtaW4=", then the Expression ${payload:base64Decode()} will return "admin:admin".

UUID3

Description: Returns a type 3 (MD5 hashed) namespace name-based UUID. The argument must be a valid UUID.

Subject Type: String

Arguments:

  • namespace : The namespace UUID identifier

Return Type: String

Examples: If we have an attribute named "attr" with a value of "string value", then the Expression ${attr:UUID3('b9e81de3-7047-4b5e-a822-8fff5b49f808')} will return "bf0ea246-a177-3300-bd7e-d4c9e973dc6f".

An empty argument or an argument value with an invalid UUID results in an exception bulletin.

See Also: UUID()

UUID5

Description: Returns a type 5 (SHA-1 hashed) namespace name-based UUID. The argument must be a valid UUID.

Subject Type: String

Arguments:

  • namespace : The namespace UUID identifier

Return Type: String

Examples: If we have an attribute named "attr" with a value of "string value", then the Expression ${attr:UUID5('245b55a8-397d-4480-a41e-16603c8cf9ad')} will return "4d111477-5100-5f2d-ae79-b38bbe15aa78".

An empty argument or an argument value with an invalid UUID results in an exception bulletin.

See Also: UUID()

hash

Description: Returns a hex encoded string using the hash algorithm provided. This can be used to generate unique keys.

Subject Type: String

Arguments:

Return Type: String

Examples: We can hash an attribute named "payload" by using the Expression ${payload:hash('SHA-256')} If the attribute payload had a value of "string value" then the Expression ${payload:hash('SHA-256')} will return "9b6a1a9167a5caf3f5948413faa89e0ec0de89e12bef55327442e60dcc0e8c9b".