Skip to content

Add mode for returning last item for duplicate keys #696

@VladUrziceanu

Description

@VladUrziceanu

Hi,

I see that cJSON handles duplicate members by always returning the first matching member with the GetObjectItem functions.

The JSON spec leaves handling of duplicate keys as an implementation detail. However, ECMA-262 EcmaScript specification, which is widely adopted by web browser JavaScript engines states:

In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten.

In other words, the last value wins. Would there be interest in adding a configurable mode to cJSON to ensure interoperability with web application parsers by modifying the GetObjectItem functions to return the last matching item in case of duplicates?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions