Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification of meaning of Null #584

Closed
GEricson opened this issue May 8, 2018 · 11 comments
Closed

Clarification of meaning of Null #584

GEricson opened this issue May 8, 2018 · 11 comments

Comments

@GEricson
Copy link

GEricson commented May 8, 2018

Clause "4.2.1 Instance Data Model" describes null as one of six primitive type. This is not correct. Instead null is an indicator for the absence of a value. This can apply to elements of any of the remaining five types, each of which specify an allowable range of values, including the possibility of no value. If the schema allows an element to have no value, then the element indicate that it is null. An empty string "", is equivalent to indicating null since in both cases, the element has no value.

@awwright
Copy link
Member

awwright commented May 8, 2018

@GEricson Do you have a citation for this?

@handrews
Copy link
Contributor

@GEricson per the introduction of RFC 8259:

JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays)

Section 3: Values defines the null literal, which is the value with type "null".

JSON makes a distinction between a value of null and a property without a value.

An empty string is definitely a value in JSON. It can even be used as the name of a property (although this is generally ill-advised).

@awwright
Copy link
Member

Also to elaborate, JSON isn't a programming language, it's a data format; and the purpose of the Data Model is to describe the complete, mathematical set of values that can be expressed by a JSON document.
The only way it would make sense to say there is "no value" is if the document isn't valid JSON. For example, an empty document isn't a valid JSON document.

@handrews
Copy link
Contributor

@GEricson checking back in on whether you have a citation in support of your assertion, or a counter-example showing that my citation of RFC 8259 is incorrectly interpreted. If we don't hear back from you in the next week, I'll close this out as answered.

@handrews
Copy link
Contributor

It's been another week with no response, for a total of two weeks of quiet. Closing.

@GEricson
Copy link
Author

@handrews and @awwright : Sorry for not responding sooner. I have not been actively monitoring.

I agree that RFC8259 defines null literal with a value of null. However, it is not a type. A simple test for whether null is a type. consider that it makes sense to say a property has a type of string. However, it doesn't make sense to say a property has a type of null.

What needs to be clarified is that null is not a type, but it is a literal that may be used in a representation, (for example in a JSON instance) to indicate the absence of a value.

As a normative reference, the most comprehensive source for modeling is the Unified Modeling Language (UML), also not a programming language. UML defines null as a literal that represents the absence of value. Thus, null is not itself a value of a typed element, but an indicator in a representation that the typed element has no value.

@Relequestual
Copy link
Member

Are you saying we shouldn't be able to distinguise between empty string and null?

@gregsdennis
Copy link
Member

@Relequestual the empty string is definitely not null. It's a string that contains 0 characters. "" vs null

@GEricson it's true that the absence of a valid implies null in many languages, like .Net, however this is JSON. In JSON the absence of a key is a distinctly different thing than the presence of the key with a value of null.

I dealt with this in Manatee.Json #56 and left some notes of my experience. In short, I found that I needed to track .Net null separately from JSON null.

@GEricson
Copy link
Author

@Relequestual It certainly is true that many clients want to distinguish between an empty string and a null.
A typed property may be allowed to have no value (i.e. null). In all other cases, it must have a value that is consistent with the type definition. So if a property has type string, and the string has no characters, then by definition, it has no value and is null.
In this case, distinguishing between an empty string and a null is making a statement, not about the value of the typed property, but of its state. For example, whether or not it has an implementation.
Some implementations also distinguish between no value and not implemented. I don't think there is consensus between the three cases: property not in representation, property in representation indicates null, and property in representation indicates an empty string.

@handrews
Copy link
Contributor

@GEricson RFC 8259 explicitly states that null is a type

JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays).

This is not up for debate. It could not possibly be more clear. Philosophical questions about whether this is the correct conceptual model are irrelevant- it is unambiguously, objectively, and explicitly defined by an RFC that is not just a proposed standard but an actual, ratified standard (green bar at the top).

@gregsdennis is also correct that null and absent are very different concepts in JSON.

@json-schema-org json-schema-org locked as resolved and limited conversation to collaborators Jun 20, 2018
@awwright
Copy link
Member

awwright commented Jun 21, 2018

Yeah, for our purposes, we've adopted a certain definition, which may or may not be the same definition in other standards or programming languages.

null is a value in JSON.

"null" is also the name of a type, a set of values. The "null" type has one item in the set: null.
Likewise, the "boolean" type is a set of two values, true and false.

PHP works the same way, though it differentiates the value null from the set named "NULL" using capital letters:

>>> gettype(null)
=> "NULL"
>>> gettype(false)
=> "boolean"
>>> gettype("")
=> "string"
>>> gettype(0)
=> "integer"

I speculate this might be some confusion with the C concept of NULL, which is a specific location in memory (usually 0 because it's falsy, but sometimes other locations depending on system architecture); C confusingly also has the null byte, which signifies the last byte of nul-terminated strings. JSON has nothing in common with these C concepts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants