> ## Documentation Index
> Fetch the complete documentation index at: https://validity-kt.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Encodings

> Base64, Base32, Base58, hexadecimal and JSON.

Text that encodes something else, checked on strings. They check that the text decodes, not what it decodes to.

```kotlin Attachment.kt theme={null}
data class Attachment(
    val content: String?,
    val checksum: String?,
    val attributes: String? = null
) : Validatable {
    override fun validation() = validation {
        ::content required { base64() }
        ::checksum required { hash(HashAlgorithm.SHA256) }
        ::attributes ifPresent { json() }
    }
}
```

| Constraint | Checks |
| - | - |
| [`base64`](#base64) | Is Base64 with the standard alphabet and its `=` padding. |
| [`base64Url`](#base64url) | Is Base64 with the URL-safe alphabet (`-` and `_`) and no padding. |
| [`base32`](#base32) | Is Base32 (RFC 4648) in uppercase, with its `=` padding. |
| [`base58`](#base58) | Is not empty and is Base58, the Bitcoin alphabet without `0`, `O`, `I` and `l`. |
| [`hexadecimal`](#hexadecimal) | Is not empty and has only hexadecimal digits, in either case. |
| [`json`](#json) | Is one valid JSON value: an object, an array, a string, a number, `true`, `false` or `null`. |

### `base64`

`base64()` on `String`

Checks that the string is Base64 with the standard alphabet and its `=` padding.

The empty string passes.

**Code** `base64`· **Message** `must be valid Base64` · **Change it** `base64 = "…"`

### `base64Url`

`base64Url()` on `String`

Checks that the string is Base64 with the URL-safe alphabet (`-` and `_`) and no padding.

The empty string passes.

**Code** `base64Url`· **Message** `must be valid URL-safe Base64` · **Change it** `base64Url = "…"`

### `base32`

`base32()` on `String`

Checks that the string is Base32 (RFC 4648) in uppercase, with its `=` padding.

The empty string passes.

**Code** `base32`· **Message** `must be valid Base32` · **Change it** `base32 = "…"`

### `base58`

`base58()` on `String`

Checks that the string is not empty and is Base58, the Bitcoin alphabet without `0`, `O`, `I` and `l`.

**Code** `base58`· **Message** `must be valid Base58` · **Change it** `base58 = "…"`

### `hexadecimal`

`hexadecimal()` on `String`

Checks that the string is not empty and has only hexadecimal digits, in either case.

**Code** `hexadecimal`· **Message** `must be hexadecimal` · **Change it** `hexadecimal = "…"`

### `json`

`json()` on `String`

Checks that the string is one valid JSON value: an object, an array, a string, a number, `true`, `false` or `null`.

**Code** `json`· **Message** `must be valid JSON` · **Change it** `json = "…"`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.