Proposal - Truthiness (Mainly to Decide Empty Object) #29
Replies: 7 comments 28 replies
-
This guy is kinda holding up my |
Beta Was this translation helpful? Give feedback.
-
@TotalTechGeek I guess time works differently for everyone. For me personally, I can look at things coming in as a trickle, but unfortunately, I don't have time for a deluge of discussions on 3 separate GitHub issues. If you'd like my input on something specifically, please ping me. |
Beta Was this translation helpful? Give feedback.
-
I think treating empty objects as truthy would be the expected behavior for most users. |
Beta Was this translation helpful? Give feedback.
-
Self +1. Current Votes
(Dropped @dslmeinte's vote due to a modification from truthy to falsy) |
Beta Was this translation helpful? Give feedback.
-
For CertLogic, I chose to consider the empty object truthy: https://github.com/ehn-dcc-development/eu-dcc-business-rules/blob/main/certlogic/specification/README.md#truthy-and-falsy-values For the case of JSON Logic, I'm guessing that all objects being (universally) truthy is probably the most consistent choice. |
Beta Was this translation helpful? Give feedback.
-
Can someone explain why it makes sense to them that |
Beta Was this translation helpful? Give feedback.
-
@json-logic/tc I've modified the proposal to switch @codetiger and @toddbaert I believe y'all communicated y'all were largely indifferent towards this choice, so I haven't dropped your votes. I added an opinion though to this discussion to refer back to later, I think if implementations support non-JSON items as context, they should take care to support their truthiness in an idiomatic way. |
Beta Was this translation helpful? Give feedback.
-
Background
I'm hopeful this proposal can pass through quickly, it mostly solidifies some conventions that already exist in
tests.json
, but we do need to decide if:Proposal
Based on community input, I believe we're deciding to make empty objects falsy, while other objects are truthy.
Historically,
json-logic-js
andjson-logic-php
treat empty object as truthy, but this is not codified intests.json
.Tests
Out of Scope / Author's Opinion
The following is my stance / guidance for implementers:
If your JSON Logic implementation supports non-JSON constructs being passed into context (ecosystem specific, for example, native
Map
orSet
structures or class instantiations), I recommend the following interpretation:"Any empty iterable structure should be falsy in JSON Logic".
Therefore, strings, arrays, dictionaries, sets, tree structures, and more can be appropriately handled for falsiness. Otherwise, class instances should be truthy.
Beta Was this translation helpful? Give feedback.
All reactions