Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. extern crate serde_json; // 1.0.38
  2. use serde_json::Value;
  3.  
  4. fn sort_json(s: &str) -> String {
  5. let obj: Value = serde_json::from_str(s).expect("Unable to deserialize JSON object");
  6. serde_json::to_string(&obj).expect("Unable to serialize JSON object")
  7. }
  8.  
  9. fn main() {
  10. println!("{:?}", sort_json(r#"{"c": 3, "b": 2, "a": 1, "nested": {"z": 1, "a": 2}}"#));
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement