[jq] Base64-encode or decode a string inside JSON

Created on November 30, 2026

Use @base64 and @base64d with the update operator |= to transform a particular field.

Encode the message

printf '%s\n' '{"id":1,"message":"Hello, jq!"}' | jq '.message |= @base64'
{
  "id": 1,
  "message": "SGVsbG8sIGpxIQ=="
}

.message |= @base64 replaces the message with its encoded text. The ID is preserved.

Decode the message

printf '%s\n' '{"id":1,"message":"SGVsbG8sIGpxIQ=="}' | jq '.message |= @base64d'
{
  "id": 1,
  "message": "Hello, jq!"
}

The message is back in its original form. This example uses UTF-8 text.

Reference

jq