Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Picojson] Let the key of objects in json be ordered by default #16863

Merged

Conversation

Ubospica
Copy link
Contributor

@Ubospica Ubospica commented Apr 9, 2024

Previously picojson define object as an alias of std::unordered_map. That means when parsing json, the order of keys in objects are uncertain and dependent on implementation. This makes it inconvenient for certain applications, e.g. in LLM generation output, we wish the order of keys the same as the order in the json file.

This PR implements a ordered hashmap ordered_hashmap that 1) maintains the order in which the elements are inserted, and 2) have the same interface as std::unordered_map. Picojson will define object as an alias of ordered_hashmap, so the order of the input json is maintained when parsing.

Macro PICOJSON_USE_ORDERED_OBJECT controls whether object uses the ordered version or the unordered version. It is set by default.

@Ubospica Ubospica force-pushed the main-dev/2024-04-10-picojson-order-update branch 3 times, most recently from 0aa1b19 to 622a54d Compare April 9, 2024 17:05
3rdparty/picojson/picojson.h Outdated Show resolved Hide resolved
@Ubospica Ubospica force-pushed the main-dev/2024-04-10-picojson-order-update branch 3 times, most recently from 0ee5357 to c0f8f9a Compare April 9, 2024 19:37
Previously picojson define `object` as an alias of `std::unordered_map`. That means when parsing json, the order of keys in objects are uncertain and dependent on implementation. This makes it inconvenient for certain applications, e.g. in LLM generation output, we wish the order of keys the same as the order in the json file.

This PR implements a ordered hashmap `ordered_hashmap` that 1) maintains the order in which the elements are inserted, and 2) have the same interface as `std::unordered_map`. Picojson will define object as an alias of `ordered_hashmap`, so the order of the input json is maintained when parsing.

Macro `PICOJSON_USE_ORDERED_OBJECT` controls whether object uses the ordered version or the unordered version. It is set by default.
@Ubospica Ubospica force-pushed the main-dev/2024-04-10-picojson-order-update branch from c0f8f9a to 1d7c33b Compare April 9, 2024 19:40
@tqchen tqchen merged commit a482b4c into apache:main Apr 10, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants