koajs / koajs/is-json

Inconsistent handling of boolean (and other types)

Open
#1 1 comment 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
19
Forks
5
PR merge metrics
No merged PRs in 30d

Description

Why is `true` JSON but not `false`? Or `5` JSON but not `0`? Of all the falsey values, only `undefined` cannot be stringified and is not valid JSON by any RFC/specification. `true`, `5`, and `2.5` may or may not be valid JSON depending on what authority you cite, but I cannot conceive of a justifcation for including them while excluding ~~`null`~~, `false`, `0`, and `0.0`.

The inconsistency seems problematic due to the use of this package within KOA itself. The behavior is wrong, yet deviation in custom middleware could cause as many bugs as it fixes.

(Update: I should acknowledge that there does need to be one value which indicates that there is no value, and that while `undefined` is most likely the clear winner, excluding `null` is likely to produce breaking changes in Koa with meaningful impact).

Contributor guide

Open the contributing guide

Research direction

Start at the is-json package entry point and its use within Koa, then inspect how true, false, 0, 5, null, and undefined are classified. Compare that behavior with the relevant JSON rules and decide the compatibility target; done means the accepted values are consistent without introducing the reported Koa breakage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.