Posted Tue, 08 Sep 2015 22:17:53 GMT in reply to
Suliman
Reply
On Mon, 07 Sep 2015 20:50:31 GMT, Suliman wrote:
I would like to get something like:
{"collection":"tags","example":{"name":"dima"}}
I am doing:
Json x = Json.emptyObject;
x.collection = "tags";
x.example = `{"name":"dima"}`;
writeln(x.toString);
I am getting:
{"collection":"tags","example":"{\"name\":\"dima\"}"}
What I am doing wrong? How to prevent slashes appearing?
Yes, you're assigning a string to a Json object's member.
You need to create a new object first, and then assign members to it.
auto x = Json.emptyObject;
x.collection = "tags";
x.example = Json.emptyObject;
x.example.name = "dima";
writeln(x.toString);
Also, I believe the x.prop syntax is going to be deprecated, so you should instead use:
auto x = Json.emptyObject;
x["collection"] = "tags";
auto example = Json.emptyObject;
example["name"] = "dima";
x["example"] = example;