k6 JavaScript adds byte, Set, and raw JSON built-ins
Introduced 2026-09-21 · score 0.95
HOW TO USE IT
When preparing binary test data or checking response fields, use the documented `Uint8Array` conversions and `Set` operations. To serialize an exact numeric JSON value, pass its decimal text to `JSON.rawJSON()` before `JSON.stringify()`; k6 v2.3.0 release notes document these examples.
const bytes = Uint8Array.fromHex('6b36');
console.log(bytes.toBase64()); // azY=const expected = new Set(['id', 'name', 'email']);
const received = new Set(['id', 'name']);
console.log([...expected.difference(received)]); // ["email"]JSON.stringify({ id: JSON.rawJSON('9007199254740993') });
// '{"id":9007199254740993}'WHY THIS HELPS
When writing test data or response assertions, encode binary values, compare sets, or preserve an exact numeric JSON value.
REQUIREMENTS AND LIMITATIONS
- Version: v2.3.0
- Uint8Array.fromHex(hex) (required): Creates byte data from a hex string; the release example uses `'6b36'`.
- Uint8Array.prototype.toBase64() (required): Converts `Uint8Array` data to base64.
- Set.prototype.difference(other) (required): Returns the set difference; the example finds expected fields absent from the received set.
- Set.prototype.intersection(other): Set operation named in the release notes; parameter details are not stated there.
- Set.prototype.union(other): Set operation named in the release notes; parameter details are not stated there.
- JSON.rawJSON(text) (required): Creates a raw JSON value; the example passes numeric text so it serializes without rounding through a JavaScript `Number`.
FIRST-PARTY EVIDENCE
Check the installed version and the source before using it. Entry JSON