JSON undefined value type

Json

Json Problem Overview


I came across this JSON code. I noticed that it makes use of undefined value. Where can I find more information about this value type?

  tracks:[
     (         {
        codec:"h264",
        language:undefined,
        id:1,
        bitrate:785236,
        content:"video"
     }         ),
     (         {
        codec:"aac",
        language:undefined,
        id:2,
        bitrate:75969,
        content:"audio"
     }         )
  ],

Json Solutions


Solution 1 - Json

  • undefined is not a valid JSON value, even though it is valid in javascript.

    From the official JSON standard (ECMA-404, Section 5):

    > A JSON value can be an object, array, number, string, true, false, or null.

  • For JSON, use null instead of undefined: { "something": null }

Solution 2 - Json

undefined is a special type where it simply indicates that the variable language is not initialized or may be it's not yet defined.

null in javascript simply indicates absence of a value, and it can also be used to indicate “no value” for numbers and strings as well as objects.The undefined value also represents absence of value, it is the value of the variables that have not been initialized and the value when you get from object property or array element that doesn’t exist undefined is a predefined global variable that is initialized to undefined value.

null and undefined doesn’t have any properties or methods.In fact, using . or [] to access property or method of these values causes a TypeError.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZomboView Question on Stackoverflow
Solution 1 - JsonRingoView Answer on Stackoverflow
Solution 2 - JsonMurali NView Answer on Stackoverflow