json-parser/json-builder

Duplicate objects are allowed

marauderlabs opened this issue · 3 comments

Duplicate objects with same keys(names) are accepted and added at the end instead of replacing existing ones.

RFC 7159: says

The names within an object SHOULD be unique.

LB-- commented

IMO this is a useful feature to support. While properly formatted JSON "should" have unique keys, there is nothing wrong with accepting JSON with duplicate keys and letting the client code decide which key(s) to use.

Because it's a "SHOULD" in the RFC, I don't think there's any harm in allowing this. I would accept a PR for an alternative to json_object_push that replaces existing keys, providing the original functionality is unchanged.

Yes. I agree. To support both, I've added another API to add just Unique keys. Will test and initiate a PR.