When making a json how should null values be handled

Hi,
Suppose i make a json like {"name" : "xya", "title" :"sample"}
Now suppose someone wants to make this json and send it to the server without the title element.
There are two ways {"name" : "xya"} or {"name" : "xya", "title": null}
Now obviously it is upto the code at server side how it handles. But ideally i feel they should be handled in the same way. Or there is any reason to handle the two different. I mean in a well designed codebase should there be any difference in how this should be handled ?

Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
I will go with this .

 {"name" : "xya", "title": null}

because name and title is fixed , whether they have value or not it is a separate thing.

Which database are you using ? MS SQL Server or MySQL Server
0
Rohit BajajAuthor Commented:
Mysql server
0
gurpsbassiCommented:
This has absolutely nothing to do with databases.
It's up to how you've configures the server side code to handle this scenario. For example with Jackson you tell it to increase missing fields when deserialising.
0
ste5anSenior DeveloperCommented:
Why not running the obvious according test?

<!DOCTYPE html>
<html>
    <body>
        <script>
            var sample = new Object();
            sample = { 'propertyA': "Some Text", 'propertyB': null };
            console.log(JSON.stringify(sample, null, ''));
        </script>
    </body>
</html>

Open in new window


In strict terms {"name" : "xya"} != {"name" : "xya", "title": null}. Cause the first has no title property (non-existence vs. null, tri-state logic). But you've asked that question wrong. JSON means JavaScript Object Notation and is used for serializing JavaScript objects as text. But as JS supports duck typing, the given case is maybe not relevant, cause you can deserialize the first JSON into an object having an name and a title property.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.