From e4af1ddb189d75ef07b218f3f353a0b5e23f00f4 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 8 Jan 2021 11:21:41 +0100 Subject: [PATCH] :ok_hand: fix operator[] --- include/nlohmann/json.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index c1be2f4b1..8318013c7 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3653,6 +3653,13 @@ class basic_json // fill up array with null values if given idx is outside range if (idx >= m_value.array->size()) { +#if JSON_DIAGNOSTICS + // remember array size before resizing + const auto previous_size = m_value.array->size(); +#endif + + m_value.array->resize(idx + 1); + #if JSON_DIAGNOSTICS // set parent for values added above for (auto i = previous_size; i <= idx; ++i)