Skip to content

ordered json pointer corruption #4289

@mishase

Description

@mishase

Description

When using ordered json with push_back call, pointer to previous structure gets corrupted

Reproduction steps

Use the code bellow with nlohmann::ordered_json to get corrupted pointer

Expected vs. actual results

Expected output (same code, without ordered json):

string
string
{"a":{"b":"test"},"c":[1]}

Actual output (corrupted pointer):

string
number
{"a":{"b":"test"},"c":[1]}

Minimal code example

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

using json = nlohmann::ordered_json; // use nlohmann::json to get correct result

int main()
{
	auto obj = json::parse("{\"a\": {\"b\": \"test\"}}");
		
	auto& ref = obj["a"]["b"];
	std::cout << ref.type_name() << '\n'; // string

	obj["c"] = json::array();
	obj["c"].push_back(1);

	std::cout << ref.type_name() << '\n'; // expected string, got number

	std::cout << obj.dump(); // valid result, {"a":{"b":"test"},"c":[1]}
}

Error messages

No response

Compiler and operating system

Tested on ARM Windows and X64 Windows in Debug and Release modes

Library version

3.11.3

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationsolution: duplicatethe issue is a duplicate; refer to the linked issue insteadsolution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions