Skip to content

The name of an object is lost when calling cJSON_ReplaceItemInObject() #174

Closed
@claudiusaiz

Description

@claudiusaiz

What I would like to do is replace a child object with another object:

new_child = cJSON_CreateObject();
cJSON_ReplaceItemInObject(parent, "child", new_child);

But the problem with this is that the name of the object gets lost after the replacement. I see that the name is not copied in cJSON_ReplaceItemViaPointer().

For those having the same problem an alternative to this is:

new_child = cJSON_CreateObject();
cJSON_DeleteItemFromObject(parent, "child");
cJSON_AddItemToObjectCS(parent, "child", new_child);

, with the disadvantage that the position of the object in the array will not be the same. The JSON standard says it shouldn't matter, but in the end it depends on the endpoint's parser implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions