Bug 23393 – JSONValue: Appending object to array fails

Status
NEW
Severity
minor
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-10-07T08:38:56Z
Last change time
2024-12-01T16:40:31Z
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: phobos#10502 →

Comments

Comment #0 by default_357-line — 2022-10-07T08:38:56Z
Consider this code: ``` JSONValue test = parseJSON(`{"a": [{"b": 5}]}`); test["a"] ~= test["a"][0]; ``` Expected: `{"a": [{"b": 5}, {"b": 5}]}` Got: std.json.JSONException@std/json.d(355): JSONValue is not an array Notably, this works: ``` test["a"] ~= JSONValue([test["a"][0]]); ```
Comment #1 by default_357-line — 2022-10-07T08:44:53Z
It is a bit unclear what `[a] ~= b` should even do if b *is* an array: `a ~ b` or `a ~ [b]`. In D, this is normally disambiguated by the typesystem. Unfortunately, JS does not have an array concat operator. Requiring ~ to be array-plus-array may genuinely be the best solution.
Comment #2 by robert.schadek — 2024-12-01T16:40:31Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10502 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB