Skip to content

Hi, is there any method to dump json to string with the insert order rather than alphabets #356

Closed

Description

@ZhaoGuangYue1986

Hi, is there any method to dump json to string with the insert order rather than alphabets

Activity

  1. nlohmann commented on Nov 8, 2016

    @nlohmann
    Owner

    No, this is not possible with the default parameters:

    The order name/value pairs are added to the object is not preserved by the library. Therefore, iterating an object may return name/value pairs in a different order than they were originally stored. In fact, keys will be traversed in alphabetical order as std::map with std::less is used by default. Please note this behavior conforms to RFC 7159, because any order implements the specified "unordered" nature of JSON objects.

    You would need to pass a version of map without alphabetical order to the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions