Serde, JSON keys and RFC 5646 (language tags)


#1

I was hoping someone may be able to point me in the direction of some documentation or example code for using Serde with JSON keys that have been formatted according to RFC 5646. Here is an example piece of JSON I expect to receive (this is set by a public specification so altering it isn’t possible):

{
  "key", "value",
  ...
  "client_name": "My Example",
  "client_name#ja-Jpan-JP": "クライアント名",
}

What I’d like to be able to do is deserialise every client_name#tag pair into a vec of structs that has everything after the # stored as a tag and the value as, well, a value ;-).

This would take the following sort of format:

pub struct Client {
    pub key: String,
    ...
    pub client_names: Vec<ClientName>,
}

pub struct ClientName {
    /// Provides support for multiple languages and scripts.
    pub tag: Option<String>,

    /// The value of this name instance.
    pub value: String,
}

I’ve not been able to find anything about hacking about with keys in this manner during deserialization so any pointers would be fantastic.


#2

Try to give a look at this, I found it helpful when I was working on Json deserialization.


#3

I think the easiest way is to deserialize the json to Map<String, Value>
then convert it to Client manually


#4

Thanks for the help here. The serde folks also made a useful suggestion so I can move forward on this one now.