MDN self-hosted library · e01.org

DOMMatrixReadOnly: toJSON() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const matrix = new DOMMatrixReadOnly("translate(20px, 30px)");
const matrix3D = new DOMMatrixReadOnly("translate3d(22px, 55px, 66px)");

const json = matrix.toJSON();
console.log(json); // A plain object
console.log(typeof json); // "object"
console.log(json.is2D); // Same value as matrix.is2D
js
console.log(JSON.stringify(matrix));
js
console.log(JSON.stringify(matrix3D));