apple/pkl · error · RendererException
Values of type `Bytes` cannot be rendered as JSON. Value: %s
Error message
Values of type `Bytes` cannot be rendered as JSON. Value: %s
What it means
JsonRenderer throws this RendererException when asked to render Pkl Bytes (a byte array) as JSON, because raw binary has no standard JSON encoding. The value's byte[] is included in the message via its string form.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/JsonRenderer.java:107
throw new UncheckedIOException(e);
}
}
@Override
public void visitDuration(Duration value) {
throw new RendererException(
String.format("Values of type `Duration` cannot be rendered as JSON. Value: %s", value));
}
@Override
public void visitDataSize(DataSize value) {
throw new RendererException(
String.format("Values of type `DataSize` cannot be rendered as JSON. Value: %s", value));
}
@Override
public void visitBytes(byte[] value) {
throw new RendererException(
String.format(
"Values of type `Bytes` cannot be rendered as JSON. Value: %s", (Object) value));
}
// Pair coming from the runtime can never admit null (in-language null is represented as PNull)
@SuppressWarnings("DataFlowIssue")
@Override
public void visitPair(Pair<?, ?> value) {
try {
writer.beginArray();
visit(value.getFirst());
visit(value.getSecond());
writer.endArray();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Encode the Bytes as base64 (or hex) text before rendering
- Use prop type String/Listing<String> with an explicit encoding instead of Bytes
- Exclude binary fields from the JSON output
Example fix
// before prop key: Bytes = ... // after prop keyBase64: String = key.base64Encoded
Defensive patterns
Strategy: type-guard
Validate before calling
if (value instanceof byte[] || "Bytes".equals(value.getClass().getSimpleName())) {
throw new IllegalArgumentException("encode Bytes (e.g. base64) before JSON rendering");
} Type guard
boolean isJsonRenderable(Object v) {
return !(v instanceof Duration || v instanceof DataSize || v instanceof byte[]);
} Try / catch
try {
renderer.render(value);
} catch (RendererException e) {
LOG.error("JSON rendering unsupported: {}", e.getMessage());
} Prevention
- Base64-encode binary content into String fields before JSON rendering
- Avoid Bytes-typed properties in modules designated as JSON APIs
- Validate the value tree for unsupported types (Duration, DataSize, Bytes) prior to rendering
When it happens
Trigger: Rendering to JSON any property that evaluates to Bytes (e.g. `data = new Bytes { ... }` or base64 output of binary resources) via visitBytes.
Common situations: Modules embedding binary blobs — keys, certificates, hashes, or file contents — rendered to JSON for consumption by other tools.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- Values of type `Duration` cannot be rendered as JSON. Value:
- Values of type `DataSize` cannot be rendered as JSON. Value:
- cannotRenderValue
- JavaType token must be parameterized.
- Failed to convert `pkl.base#String` to `java.net.URI`.
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/60f2cd0c761c4f07.
Report an issue: GitHub.