rapidjson proper json creation
<p>I'm trying to create a json using rapidjson and I am having some unexpected problems with generating a proper output.</p>

<p>I'm creating and populating a document like this:</p>

<pre><code>Document d;
d.SetObject();

rapidjson::Document::AllocatorType&amp; allocator = d.GetAllocator();

size_t sz = allocator.Size();

d.AddMember("version",  1, allocator);
d.AddMember("testId",   2, allocator);
d.AddMember("group",    3, allocator);
d.AddMember("order",    4, allocator);

Value tests(kArrayType);
Value obj(kObjectType);
Value val(kObjectType);

obj.AddMember("id", 1, allocator);

string description = "a description";
val.SetString(description.c_str(), static_cast&lt;SizeType&gt;(description.length()), allocator);
obj.AddMember("description", val, allocator);

string help = "some help";
val.SetString(help.c_str(), static_cast&lt;SizeType&gt;(help.length()), allocator);
obj.AddMember("help", val, allocator);

string workgroup = "a workgroup";
val.SetString(workgroup.c_str(), static_cast&lt;SizeType&gt;(workgroup.length()), allocator);
obj.AddMember("workgroup", val, allocator);

val.SetBool(true);
obj.AddMember("online", val, allocator);

tests.PushBack(obj, allocator);
d.AddMember("tests", tests, allocator);

// Convert JSON document to string
rapidjson::StringBuffer strbuf;
rapidjson::PrettyWriter&lt;rapidjson::StringBuffer&gt; writer(strbuf);
d.Accept(writer);
</code></pre>

<p>When I run this code, I'm expecting to obtain this json:</p>

<pre><code>{
    "version": 1,
    "testId": 2,
    "group": 3,
    "order": 4,
    "tests": [
        {
            "id": 1,
            "description": "a description",
            "help": "some help",
            "workgroup": "a workgroup",
            "online": true
        }
    ]
}
</code></pre>

<p>but the actual generated output is...</p>

<pre><code>{
    "version": 1,
    "testId": 2,
    "group": 3,
    "order": 4,
    "tests": [
        {
            "id": 1,
            "description": "a description",
            "help": "some help",
            "workgroup": "a workgroup",
            "online": tr{
    "version": 1,
    "testId": 2,
    "group": 3,
    "order": 4,
    "tests": [
        {
            "id": 1,
            "description": "a description",
            "help": "some help",
            "workgroup": "a workgroup",
            "online": true
        }
    ]
}
</code></pre>

<p>Any ideas?</p>