JSON::addArrayElement(JSON const& val)
{
    JSON_array* arr = dynamic_cast<JSON_array*>(
        this->m->value.getPointer());
    if (0 == arr)
    {
        throw std::runtime_error("JSON::addArrayElement called on non-array");
    }
    if (val.m->value.getPointer())
    {
        arr->elements.push_back(val.m->value);
    }
    else
    {
        arr->elements.push_back(new JSON_null());
    }
    return arr->elements.back();
}
JSON::addArrayElement(JSON const& val)
{
    JSON_array* arr = dynamic_cast<JSON_array*>(
        this->m->value.getPointer());
    if (0 == arr)
    {
        throw std::runtime_error("JSON::addArrayElement called on non-array");
    }
    if (val.m->value.getPointer())
    {
        arr->elements.push_back(val.m->value);
    }
    else
    {
        arr->elements.push_back(new JSON_null());
    }
    return arr->elements.back();
}