!lymvtcwDJ7ZA9Npq:lix.systems

Lix Development

431 Members
(Technical) development of Lix, the package manager, a Nix implementation. Please be mindful of ongoing technical conversations in this channel.144 Servers

Load older messages


SenderMessageTime
20 Mar 2026
@emilazy:matrix.orgemilythe fact that JSON is a bad format doesn't mean Nix shouldn't be able to parse JSON10:12:15
@emilazy:matrix.orgemily having a parseJSONWith that lets you be more specific about how to handle weird issues might be good, but is a separate matter 10:12:32
@kfears:matrix.orgKFears& 🏳️‍⚧️ (they/them)We prefer the behavior of taking the last key's value but parsing successfully otherwise, in a general-case JSON implementation. Because we consider JSON with duplicate keys to be malformed, but not to a degree where you'd reject it outright, without options to parse it more liberally10:13:34
@emilazy:matrix.orgemilyeven going by that blog post it's very very rare for implementations to reject duplicate keys10:14:02
@emilazy:matrix.orgemilythough sadly it doesn't look like they checked how it's resolved for differing values of the same key10:14:09
@emilazy:matrix.orgemilybut I expect taking the last value is by far the most common10:14:19
@emilazy:matrix.orgemilyPython matches nlohmann here for instance10:14:30
@kfears:matrix.orgKFears& 🏳️‍⚧️ (they/them)As in, if we would like to be strict and reject JSON with duplicate keys, we would also like to have an easily available option to parse it while choosing last key's value. Which works in general PL context, but is a large headache for embedded DSLs like NixLang10:14:40
@qyriad:katesiria.orgQyriadWe've seen some abuses of duplicate keys to hack "comments" into JSON, lmao10:16:02
@kfears:matrix.orgKFears& 🏳️‍⚧️ (they/them)We also feel like "last value overrides" is more intuitive of the "accept" options, because it matches the behavior of "set" operations on a hashmap and makes sense for top-to-bottom reading, while "first value overrides" feels not very programmer-ish, and "modify both keys to be unique" is very unexpected and footgunny10:17:05
@kfears:matrix.orgKFears& 🏳️‍⚧️ (they/them)
In reply to @qyriad:katesiria.org
We've seen some abuses of duplicate keys to hack "comments" into JSON, lmao
This is horrifying
10:17:30
@emilazy:matrix.orgemilyactually the only ones that did are ones that crashed, lol10:18:11
@emilazy:matrix.orgemilyoh wait no10:18:20
@emilazy:matrix.orgemilythat was just a bad choice of colours10:18:28
@emilazy:matrix.orgemily anyway I don't think something called fromJSON should reject valid JSON unless there's truly no reasonable behaviour it could do with it 10:19:01
@qyriad:katesiria.orgQyriadWe agree10:19:14
@qyriad:katesiria.orgQyriad Python json.loads and jq both accept duplicate keys, with the last one winning 10:21:25
@piegames:flausch.socialpiegameslol serde_json can't even detect duplicates10:27:05
@emilazy:matrix.orgemilyisn't the serde model fundamentally event-based? I'd expect you can write a deserializer that detects them?10:27:53
@piegames:flausch.socialpiegameshttps://github.com/serde-rs/json/issues/1074 but also, this is the main reason why I hate "take the last value". It's bogus semantics, and on any input with duplicate fields the chances that it was generated in mistake is high. Taking the last value will lead to silent failure in such cases10:28:28
@piegames:flausch.socialpiegames it is possible with serde, and there is a PR, but currently serde_json offers no way to detect it 10:28:54
@coca162:matrix.orgCocasimd-json (the rust crate) seems to ignore duplication but keep the first one instead10:31:30
@coca162:matrix.orgCocananoserde keeps the last one10:31:54
* @piegames:flausch.socialpiegames sighs10:33:59
@piegames:flausch.socialpiegamesI hate JSON so fucking much10:34:03
@piegames:flausch.socialpiegamescurrently reading the I-JSON spec and got painfully reminded that JSON has zero non-text handling capabilities10:34:37
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)I recall there seemed to be some AWS endpoint that legitimately used duplicate keys too10:34:41
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)Though I’m not sure I can find the reference now10:35:15
@piegames:flausch.socialpiegames let me rephrase the question, are there any reasonable use cases for duplicate keys where parsing both and then using only one of the values is the correct behavior? 10:36:19
@emilazy:matrix.orgemilyit's sorta like asking if there's any use case for parsing web pages with invalid HTML the same way everyone else parses them10:37:24

Show newer messages


Back to Room ListRoom Version: 10