files/en-us/web/api/rtcicecandidate/tojson/index.md
{{APIRef("WebRTC")}}
The {{domxref("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 {{jsxref("JSON.stringify", "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 {{optional_inline}}
sdpMid {{optional_inline}}
null if there is no associated media stream.
Additional information can be found in {{domxref("RTCIceCandidate.sdpMid")}}.sdpMLineIndex {{optional_inline}}
null if no such associated exists.
Additional information can be found in {{domxref("RTCIceCandidate.sdpMLineIndex")}}.usernameFragment {{optional_inline}}
[!NOTE] The returned JSON object has the same form/properties as the
candidateInfoobject that can optionally be passed to the {{domxref("RTCIceCandidate.RTCIceCandidate()","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();
{{Specifications}}
{{Compat}}