4

How to reorder elements in rapidjson array? I have JSON doc that has Test array with three objects as below

{
 "Test":[
     {
       "a":1,
       "b":"DEMO"
     },
     {
       "c":2,
       "d":"DEMO1"
     },
     {
       "e":5,
       "f":"DEMO2"
     }
   ]
}

Question- How to add one below object at the second position in above Test array without deleting existing object?

{
"x":3,
"y":"DEMO3"
}
user7588316
  • 77
  • 1
  • 5

1 Answers1

1

Since Test is an array, while it is possible to access a specific cell (ie- Test[1] = something) it's not possible to push the rest of the array without rewriting it. (Test[1] will overwrite whatever's in there)

This behaviour is possible with vectors though, so perhaps a possible solution could be to copy Test to a temporary vector, perform the operation there and then convert back to array.

From what I've seen it's not possible to use vectors with rapidjson.

Shtut
  • 1,397
  • 2
  • 14
  • 28