Bug 20385 – Add opt* methods to std.json

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-11T20:17:48Z
Last change time
2024-12-01T16:36:01Z
Assigned to
No Owner
Creator
Andre
Moved to GitHub: phobos#10399 →

Comments

Comment #0 by andre — 2019-11-11T20:17:48Z
Working with optional attributes in JSON is quite inconvenient to write: Stream stream = { appId : js["appId"].str, // like this appVersion : js.object.get("appVersion", JSONValue("")).str, // or that startTimestamp : ("startTimestamp" in js is null) ? "" : js["startTimestamp"].str, }; Adding opt* methods like optStr(string key, defaultValue = string.init) would make the usage a lot more readable: Stream stream = { appId : js["appId"].str, appVersion : js.optStr("appVersion", "1.0"), startTimestamp : js.optStr("startTimestamp") };
Comment #1 by greeenify — 2019-11-13T01:47:21Z
std.json (and most of Phobos is maintainance-only). The planned next version of std.data.json is here: https://github.com/dlang-community/std_data_json
Comment #2 by robert.schadek — 2024-12-01T16:36:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10399 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB