Back to Content

PaymentResponse: toJSON() method

files/en-us/web/api/paymentresponse/tojson/index.md

latest997 B
Original Source

{{SecureContext_Header}}{{APIRef("Payment Request API")}}

The toJSON() method of the {{domxref("PaymentResponse")}} interface is a {{Glossary("Serialization","serializer")}}; it returns a JSON representation of the {{domxref("PaymentResponse")}} object.

Syntax

js-nolint
toJSON()

Parameters

None.

Return value

A {{jsxref("JSON")}} object that is the serialization of the {{domxref("PaymentResponse")}} object.

Examples

Using the toJSON method

In this example, calling paymentResponse.toJSON() returns a JSON representation of the PaymentResponse object.

js
payment.show().then((paymentResponse) => {
  console.log(paymentResponse.toJSON());
});

To get a JSON string, you can use JSON.stringify(paymentResponse) directly; it will call toJSON() automatically.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{jsxref("JSON")}}