TrustedScriptURL: toJSON() method

Baseline 2026
Newly available

Since February 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

The toJSON() method of the TrustedScriptURL interface returns a JSON representation of the stored data.

Syntax

js
toJSON()

Parameters

None.

Return value

A string containing a JSON representation of the stored data.

Examples

The constant sanitized is an object created via a Trusted Types policy. The toString() method returns a string to safely use to load a third party script.

js
const sanitized = scriptPolicy.createScripturl(/Education?url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FAPI%2FTrustedScriptURL%2F%2522https%3A%2F%2Fexample.com%2Fmy-script.js%2522%2C);
console.log(sanitized.toJSON());

Specifications

Specification
Trusted Types
# dom-trustedscripturl-tojson

Browser compatibility