Closed
Description
Inserting into arrays using j_array[index] = value;
syntax does not correctly update the parents and will trigger the assertion for parent correctness further down the line.
Please describe the steps to reproduce the issue.
Minimal example:
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main() {
json j_array = json::array();
j_array[0] = "STRING";
j_array[1] = "STRING";
json j_array_copy = j_array;
return 0;
}
This produces the following assertion error when the copying from j_array
to j_array_copy
is performed:
assertion_failure: single_include/nlohmann/json.hpp:18670: void nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::assert_invariant(bool) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>]: Assertion `!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j) { return j.m_parent == this; })' failed.
Which compiler and operating system are you using?
- Compiler: g++ (GCC) 11.1.0
- Operating system: Linux
Which version of the library did you use?
- latest release version 3.10.2
- other release - please state the version: ___
- the
develop
branch
If you experience a compilation error: can you compile and run the unit tests?
- yes
- no - please copy/paste the error message below