Thread overview | |||||
---|---|---|---|---|---|
|
November 07, 2019 How to Delete Node from JSONValue? | ||||
---|---|---|---|---|
| ||||
import std.json; void main() { JSONValue j = ["a": "b", "x": "y"]; //j.remove("x"); //j["x"] = null; destroy(j["x"]); } What's the proper way to delete a node from a JSONValue object? I was looking for something like remove("x") that you can do with an associative array, but std.json doesn't provide that. Setting the node to null or using destroy doesn't actually remove the node so that it's not serialized when using toJSON(). |
November 07, 2019 Re: How to Delete Node from JSONValue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael A. Puls II | On Thursday, 7 November 2019 at 13:43:01 UTC, Michael A. Puls II wrote: > import std.json; > > void main() { > JSONValue j = ["a": "b", "x": "y"]; > //j.remove("x"); > //j["x"] = null; > destroy(j["x"]); > } > > What's the proper way to delete a node from a JSONValue object? > > I was looking for something like remove("x") that you can do with an associative array, but std.json doesn't provide that. Setting the node to null or using destroy doesn't actually remove the node so that it's not serialized when using toJSON(). Here the right way: j.object.remove("x"); I found std.json syntax a bit strange, so I wrote a wrap over std.json to add a bit of syntax sugar: https://github.com/2night/jsonwrap/ Andrea |
November 07, 2019 Re: How to Delete Node from JSONValue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Thursday, 7 November 2019 at 14:56:04 UTC, Andrea Fontana wrote: > Here the right way: > j.object.remove("x"); Thanks. That does the trick. > I found std.json syntax a bit strange, so I wrote a wrap over std.json to add a bit of syntax sugar: > https://github.com/2night/jsonwrap/ Thanks. I'll check it out. |
Copyright © 1999-2021 by the D Language Foundation