

Hacker News API doesn't obey RFC 4627 - dmjio

Normally, I would post this on the github issue tracker, but it does not exist. See https:&#x2F;&#x2F;github.com&#x2F;HackerNews&#x2F;API.<p>The API returns &quot;null&quot; when an &quot;Item&quot; doesn&#x27;t exist.<p>Example: https:&#x2F;&#x2F;hacker-news.firebaseio.com&#x2F;v0&#x2F;item&#x2F;1607092358902384905.json?print=pretty<p>RFC 4627 specifies that the returned JSON must be either an <i>object</i> or an <i>array</i>. This is neither. Please help. Thank you.<p>Suggestion:
Instead of &quot;null&quot;, can you make it&quot;{ \&quot;item\&quot; : null }&quot; ?<p>Warmest Regards
======
kogir
The API returns JSON values per RFC 4627 and RFC 7159. null is a valid value.
This allows clients to request only what they want:

Entire item: [https://hacker-
news.firebaseio.com/v0/item/8422599.json](https://hacker-
news.firebaseio.com/v0/item/8422599.json)

Just one property: [https://hacker-
news.firebaseio.com/v0/item/8422599/kids.json](https://hacker-
news.firebaseio.com/v0/item/8422599/kids.json)

Also, please send API correspondence to api@ycombinator.com.

------
MalcolmDiggs
I'm more surprised that they're returning a 200 when an item doesn't exist. If
they'd just return a 404, per usual, the content of the body wouldn't really
matter. (in my opinion)

~~~
davismwfl
I would argue a 404 is not proper in this case and a 200 is more correct and
valid.

The URI exists, the requested record/document does not, hence the successful
response with no return.

~~~
MalcolmDiggs
That's an interesting way to look at it. I can definitely see your point,
thank you.

------
zellio
Isn't null an object?

~~~
dmjio
The RFC says all JSON text must be an array or object, null is a value. JSON
text is made up of JSON values.

per the RFC,

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

"An object is an unordered collection of zero or more name/value pairs, where
a name is a string and a value is a string, number, boolean, null, object, or
array."

~~~
namecast
Hrmm. Later on it is explained:

2.1. Values

    
    
       A JSON value MUST be an object, array, number, or string, or one of
       the following three literal names:
    
          false null true
    
    
    

... so what you're receiving is technically a valid JSON value according to
the RFC, no?

(I am so sorry for being this pedantic - but that RFC is marked
'informational', it's not actually a standard so much as a suggestion, and
even worse, RFC 7159 obsoletes it and is an IETF standards track document -
check out
[http://tools.ietf.org/html/rfc7159](http://tools.ietf.org/html/rfc7159). The
ambiguity is definitely removed in the updated version.)

~~~
MalcolmDiggs
If I'm reading it correctly: "null" _would_ be a valid value, but a key/name
would still need to be specified. So a blank document with the word "null" on
it is invalid because the value of null has no key... but again, I may be
reading it wrong.

~~~
sarciszewski
{"key": null}

vs

null

I'm pretty sure they're both valid.

