W3C home > Mailing lists > Public > public-xformsusers@w3.org > February 2016

Re: JSON: empty number and boolean values

From: Nick Van den Bleeken <Nick.Van.den.Bleeken@inventivegroup.com>
Date: Wed, 3 Feb 2016 21:21:51 +0000
To: Erik Bruchez <erik@bruchez.org>
CC: "public-xformsusers@w3.org" <public-xformsusers@w3.org>
Message-ID: <c3a7c1bb-8f84-47e3-a790-b9d4bb4e5cd4@email.android.com>
Option 2 is also my favorite.

On 3 Feb 2016 8:59 p.m., Erik Bruchez <erik@bruchez.org> wrote:

Say we receive the following JSON:

    { "name": "Mark", "age": 21 }

which converts to:

    <json type="object">
        <age type="number">21</age>

We have an input field bound to:


Then the user blanks the field, which, say, is not required. So we have:

    <json type="object">
        <age type="number"></age>

Now when we try to serialize back the XML to JSON, what should happen?
I see 3 options:

1. Generate an empty string for "age".
2. Generate `null` "age".
3. Raise an error.

I don't like #1 because that changes types in an unexpected way.

I don't like #3 because it seems like we should have the possibility
to handle optional values.

My preference would go to #2:

    { "name": "Mark", "age": null }

The rule would be: "if we have a `number` or `boolean` element whose
string value cannot be converted back to a number or a boolean JSON
value, either because it is empty or blank or because it doesn't match
the lexical value of a JSON number of boolean, then generate a

Feedback welcome.


Received on Wednesday, 3 February 2016 21:22:27 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:37:45 UTC