Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opt* methods to std.json #10399

Open
dlangBugzillaToGithub opened this issue Nov 11, 2019 · 1 comment
Open

Add opt* methods to std.json #10399

dlangBugzillaToGithub opened this issue Nov 11, 2019 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

andre reported this on 2019-11-11T20:17:48Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20385

CC List

  • greeenify

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")
};
@dlangBugzillaToGithub
Copy link
Author

greeenify commented on 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

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants