This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
The RTCIceCandidate method toJSON() converts the RTCIceCandidate on which it's called into JSON.
A stringified version of the object can then be obtained by calling stringify() on the returned object.
toJSON()
None.
A JSON object with the following properties, which have been set to the corresponding values in the RTCIceCandidate object:
candidate OptionalA string describing the network connectivity information for the candidate. Additional information can be found in RTCIceCandidate.candidate.
sdpMid OptionalA string containing the identification tag of the media stream with which the candidate is associated, or null if there is no associated media stream. Additional information can be found in RTCIceCandidate.sdpMid.
sdpMLineIndex OptionalA number property containing the zero-based index of the m-line with which the candidate is associated, within the SDP of the media description, or null if no such associated exists. Additional information can be found in RTCIceCandidate.sdpMLineIndex.
usernameFragment OptionalA string containing the username fragment (usually referred to in shorthand as "ufrag" or "ice-ufrag"). This fragment, along with the ICE password ("ice-pwd"), uniquely identifies a single ongoing ICE interaction (including for any communication with the STUN server). Additional information can be found in RTCIceCandidate.usernameFragment.
Note: The returned JSON object has the same form/properties as the candidateInfo object that can optionally be passed to the RTCIceCandidate() constructor to configure the candidate.
This simple example obtains a JSON string representing an RTCIceCandidate found in the variable candidate.
let jsonString = candidate.toJSON().stringify();
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
toJSON |
43 | 15 | 27 | 30 | 11 | 43 | 27 | 30 | 11 | 4.0 | 43 | 11 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/toJSON