Decoding a JSON into a hash map (top-level key names not known)

47 Views Asked by At

I have a file that I need to parse that contains a JSON file as so:

{
  "2123123": "sdjfhasjlkdfhasjldf",
  "2342364": "dsfkjgskdlgfjsödlkfs",
  ...
}

These are key hashes with the matching public key. I would like to load it into a HashMap<String, String>. I know that I can do a struct like:

#[derive(Deserialize)]
struct Keys {
  key_1: String,
  key_2: String,
  ...
}

But this only works if I know a priori the hashes of the keys. I would not like to edit source in order to support adding a new key to the JSON. Is there a simple way to parse a JSON like this directly into a hashmap?

0

There are 0 best solutions below