Languages

Why JSON.parse method does not support undefined property value?

2 points
Asked by:
JustMike
26120

How to make possible to parse json with undefined value?

// ONLINE-RUNNER:browser;

var json = '{"value":undefined}';
var data = JSON.parse(json);

console.log(data);

 

1 answer
3 points
Answered by:
JustMike
26120

It is impossible becouse of JSON format.

Try to use null instead.

// ONLINE-RUNNER:browser;

var json = '{"value":null}';
var data = JSON.parse(json);

console.log(data.value);

Some trick is to do not put value property.

// ONLINE-RUNNER:browser;

var json = '{}';
var data = JSON.parse(json);

console.log(data.value);

 

0 comments Add comment
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join