[Picojson] Let the key of objects in json be ordered by default #16863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously picojson define
object
as an alias ofstd::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 asstd::unordered_map
. Picojson will define object as an alias ofordered_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.