Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  76] [ 7]  / answers: 1 / hits: 29482  / 8 Years ago, sat, july 23, 2016, 12:00:00

The following example shows that JSON.stringify() returns the string {} for SpeechSynthesisVoice objects:



var voiceObject = window.speechSynthesis.getVoices()[0];
JSON.stringify(voiceObject); //returns {}?


Complete example: JSFiddle



Why does it return {} and not something like {voiceURI: Google Deutsch, name: Google Deutsch, lang: de-DE, localService: false, default: false}?



Note that the above example does not work for chrome or iOS; it is targeted for Mozilla Firefox.


More From » json

 Answers
13

JSON.stringify includes an object's own, enumerable properties (spec) that have values that aren't functions or undefined (as JSON doesn't have those), leaving out ones it inherits from its prototype, any that are defined as non-enumerable, and any whose value is a function reference or undefined.



So clearly, the object you get back from getVoices()[0] has no own, enumerable properties that can be represented in JSON. All of their properties must be either inherited, defined as non-enumerable, or (though it's probably not the case here) functions or undefined.


[#61272] Thursday, July 21, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
erinh

Total Points: 38
Total Questions: 100
Total Answers: 110

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
;