Skip to content

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

Merged
tqchen merged 1 commit into
apache:mainfrom
Ubospica:main-dev/2024-04-10-picojson-order-update
Apr 10, 2024
Merged

tqchen merged 1 commit into
apache:mainfrom
Ubospica:main-dev/2024-04-10-picojson-order-update

Conversation

@Ubospica

@Ubospica Ubospica commented Apr 9, 2024

Copy link
Copy Markdown
Contributor

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
Comment thread 3rdparty/picojson/picojson.h Outdated
@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
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