Encryption: Hash Functions in JSONata ($md5 and $sha256)

JSONata provides cryptographic hash functions that allow values to be transformed into unique and deterministic representations.

These functions can be used to:

  • Ensure data integrity

  • Create unique identifiers

  • Anonymize sensitive values

  • Ensure compatibility with external systems

Supported functions:

  • $md5(value)

  • $sha256(value, digestFormat?)

Difference Between MD5 and SHA-256

Algorithm
Hash Size
Security
Common Usage

MD5

32 characters (128 bits)

Weak, collision-prone

Checksums, simple validation

SHA-256

64 characters (256 bits)

Strong, recommended

Authentication, blockchain, cryptography

Function $md5(value)

  • Calculates the MD5 hash of the provided value.

  • Return: fixed 32-character hexadecimal string

  • Digest parameter: not supported

Example

Function $sha256(value, digestFormat?)

  • Calculates the SHA-256 hash of the provided value.

  • Return: fixed 64-character hexadecimal string (by default)

  • Digest parameter: supports digestFormat to change the output format

Supported formats (digestFormat)

Value
Description
Example Output

"hex" (default)

Hexadecimal representation

27badc983df1780b60c2...

"base64"

Standard Base64

J7cmD3xeAtgwrP6nToZoA...

"base64url"

Base64 adapted for URLs/JWTs

J7cmD3xeAtgwrP6nToZoA...

Practical Examples

SHA-256 in hex (default)

SHA-256 in Base64

SHA-256 in complex JSON (hex)

Resumo dos tipos de digest

Digest Format
Description

hex

Hexadecimal representation (default)

base64

Standard Base64 representation

base64url

Base64 adapted for URLs/JWTs

Last updated