1

I want to create following Json object

 {
    "name":"abc",
    "property1"=[2010, 2013, 2015],
    "property2"=["str1, "str2", str3"],
    "property3"=[true, false]
 }

property1, property2, property3 is basically an array but with distinct elements. Currently I am creating through:

document.AddMember("property1", Value(kArrayType), allocator);
document.AddMember("property2", Value(kArrayType), allocator);
document.AddMember("property3", Value(kArrayType), allocator);

Then I iterate over the list and push the value in the object through:

for (auto& iter: object_info_list) {
    document["property1"].PushBack(iter->property1, allocator); //int value
    document["property2"].PushBack(iter->property2, allocator); // string value
    document["property3"].PushBack(iter->property3, allocator); // bool value
}

But the above statement pushes all the values (duplicates) as well. Is there a way to add distinct values only (like set in c++)

Thank you in advance

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Dodez
  • 19
  • 2

1 Answers1

0

JSON doesn't have many data types. You will need to de-duplicate in the C++ data structure you are copying from.

E.g.

std::set<int> property1;
std::set<std::string> property2;
std::set<bool> property3;

for (auto& iter: object_info_list) {
    property1.insert(iter->property1);
    property2.insert(iter->property2);
    property3.insert(iter->property3);
}

for (auto val : property1) {
    document["property1"].PushBack(val, allocator);
}

for (auto val : property2) {
    document["property2"].PushBack(val, allocator);
}

for (auto val : property3) {
    document["property3"].PushBack(val, allocator);
}
Caleth
  • 52,200
  • 2
  • 44
  • 75