Convert vector of integers to string using nlohman json

90 Views Asked by At

I am trying to convert an std::vector of integers. For this task I am using nlohmann library. What I am expecting to get is the string "[3,5,18,11]", but I am receiving "[[3,5,18,11]]" as a result. I do not understand why I am getting another array wrapped and how to avoid it? Will appreciate any help, thanks in advance.

#include <iostream>
#include "nlohmann/json.hpp"

using namespace nlohmann;

int main() {
    const std::vector<uint64_t> data = { 3, 5, 18, 11 };

    json j = json{ data };
    auto result = j.dump();
    std::cout << result << std::endl;

    return 0;
}
1

There are 1 best solutions below

2
Chukwujiobi Canon On BEST ANSWER

This is just enough:

const std::vector<uint64_t> data = { 3, 5, 18, 11 };
json j = data;