From a070d551397a387ac2c7476b269ca33706f8ee43 Mon Sep 17 00:00:00 2001 From: kn Date: Wed, 22 Oct 2025 21:51:10 +0200 Subject: [PATCH] Fix: JSON API AddObjectValue/AddArrayValue returning parent instead of child Bug: AddObjectValue() and AddArrayValue() were returning a pointer to the parent object instead of the newly created child value, causing JSON structure corruption. Fix: 1. Call AddMember() to add the member to the parent 2. Use &(*m_pInstance)[sName.c_str()] to get pointer to the newly added child value in the parent's member map Impact: This bug affected any endpoint using AddArrayValue() or nested AddObjectValue(), such as my /api/ext/builds/list which uses arrays. The error "Referenced JSON value is not array" occurred. --- Implementation/LibMCEnv/libmcenv_jsonobject.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Implementation/LibMCEnv/libmcenv_jsonobject.cpp b/Implementation/LibMCEnv/libmcenv_jsonobject.cpp index 06ba7ffc..f1034e7a 100644 --- a/Implementation/LibMCEnv/libmcenv_jsonobject.cpp +++ b/Implementation/LibMCEnv/libmcenv_jsonobject.cpp @@ -347,10 +347,13 @@ IJSONObject * CJSONObject::AddObjectValue(const std::string & sName) jsonName.SetString(sName.c_str(), m_pDocument->GetAllocator()); jsonValue.SetObject (); - auto pMember = &m_pInstance->AddMember(jsonName, jsonValue, m_pDocument->GetAllocator()); + m_pInstance->AddMember(jsonName, jsonValue, m_pDocument->GetAllocator()); + + // Get pointer to the newly added member value (not the parent object) + auto pMember = &(*m_pInstance)[sName.c_str()]; return new CJSONObject (m_pDocument, pMember); - + } IJSONArray * CJSONObject::AddArrayValue(const std::string & sName) @@ -361,7 +364,10 @@ IJSONArray * CJSONObject::AddArrayValue(const std::string & sName) jsonName.SetString(sName.c_str(), m_pDocument->GetAllocator()); jsonValue.SetArray(); - auto pMember = &m_pInstance->AddMember(jsonName, jsonValue, m_pDocument->GetAllocator()); + m_pInstance->AddMember(jsonName, jsonValue, m_pDocument->GetAllocator()); + + // Get pointer to the newly added member value (not the parent object) + auto pMember = &(*m_pInstance)[sName.c_str()]; return new CJSONArray(m_pDocument, pMember); }