Skip to content Skip to sidebar Skip to footer

Are Values "ok", False, True, Null, 123 Valid Json

Are following strings a valid JSON? 'ok' false true null 123 If not why do standard javascript JSON.parse method allow to use this values as valid JSON? I sometimes use this values

Solution 1:

Strictly speaking, those values by themselves are not valid JSON, which would require either an object wrapper {} (and configuration as key-value pair) or array wrapper [] around them. There are however many JSON serialization libraries that allow for use of non-nested primitives as you have shown. It is probably best to not rely on this behavior unless you specifically know which JSON serialization/deserialization libraries will be in use on both ends and can verify that they both support this behavior in the same manner.


Post a Comment for "Are Values "ok", False, True, Null, 123 Valid Json"