MDN self-hosted library · e01.org

PublicKeyCredential: 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 credential = await navigator.credentials.create({
  publicKey: createCredentialOptions,
});

const json = credential.toJSON();
console.log(json); // A plain object
console.log(typeof json); // "object"
console.log(json.id); // Same value as credential.id
js
const jsonString = JSON.stringify(credential);
console.log(jsonString);

const registrationURL = "https://example.com/registration";
const apiRegOptsResp = await fetch(registrationURL, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: jsonString,
});