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
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)
$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?)
$sha256(value, digestFormat?)Calculates the SHA-256 hash of the provided value.
Return: fixed 64-character hexadecimal string (by default)
Digest parameter: supports
digestFormatto change the output format
Supported formats (digestFormat)
"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
hex
Hexadecimal representation (default)
base64
Standard Base64 representation
base64url
Base64 adapted for URLs/JWTs
Last updated