You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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")
};
The text was updated successfully, but these errors were encountered:
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
andre reported this on 2019-11-11T20:17:48Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=20385
CC List
Description
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") };The text was updated successfully, but these errors were encountered: