Skip to content

[Bug] Ordered keys are not preserved on DeepCopy() #30

@nickdnk

Description

@nickdnk

Description

If you create a JSON object using:

JSON_Object json = json_read_from_file("file.json", JSON_DECODE_ORDERED_KEYS);

the keys are ordered as expected. If you then do:

JSON_Object jsonCopy = json.DeepCopy();

the keys are now out-of-order.

I also tried calling json.EnableOrderedKeys() before and after copying, but it didn't help.

Reproduction

test_ordered_keys.json:

{
  "players": {
    "76561198034202275": "s1mple",
    "76561198246607476": "b1t",
    "76561198121220486": "Perfecto",
    "76561198044045107": "electronic",
    "76561198040577200": "sdy"
  }
}
char output[4096];
JSON_Object json = json_read_from_file("test_ordered_keys.json", JSON_DECODE_ORDERED_KEYS);
json.EnableOrderedKeys(); // This makes no difference.
JSON_Object jsonCopy = json.DeepCopy();
jsonCopy.EnableOrderedKeys(); // This also makes no difference.

json.Encode(output, sizeof(output), JSON_ENCODE_PRETTY);
LogMessage("Original: %s", output);
jsonCopy.Encode(output, sizeof(output), JSON_ENCODE_PRETTY);
LogMessage("DeepCopy: %s", output);

delete json;
delete jsonCopy;
Original: {
    "players": {
        "76561198034202275": "s1mple",
        "76561198246607476": "b1t",
        "76561198121220486": "Perfecto",
        "76561198044045107": "electronic",
        "76561198040577200": "sdy"
    }
}
DeepCopy: {
    "players": {
        "76561198246607476": "b1t",
        "76561198044045107": "electronic",
        "76561198040577200": "sdy",
        "76561198121220486": "Perfecto",
        "76561198034202275": "s1mple"
    }
}

Versions

sm-json: v4.1.1
SourceMod Compiler: 1.10
SourceMod Build: Not sure. Building with Get5's Docker.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions