Languages

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

2 points
Asked by:
JustMike
3488

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 answers
3 points
Answered by:
JustMike
3488

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
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.