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

json to Value,disordered arrangement order, how can we keep it as it is? #1018

Open
zhangwuqiao opened this issue May 7, 2023 · 1 comment

Comments

@zhangwuqiao
Copy link

I have a project where the key values in the passed in JSON are uncertain, but they must be analyzed and processed in the order in which they were passed in. However, when converting JSON to Value, the order is out of order. How to use 'from_str' Convert to Value in the order in which it is passed in?

Eg:

图片
图片

@kangalio
Copy link

See the preserve_order feature

json/Cargo.toml

Lines 58 to 61 in 931ee23

# Make serde_json::Map use a representation which maintains insertion order.
# This allows data to be read into a Value and written back to a JSON string
# while preserving the order of map keys in the input.
preserve_order = ["indexmap", "std"]

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

No branches or pull requests

2 participants